30 lines
621 B
Python
30 lines
621 B
Python
|
import sys
|
||
|
|
||
|
import click
|
||
|
import requests
|
||
|
|
||
|
import secrets
|
||
|
|
||
|
|
||
|
@click.command()
|
||
|
@click.option('--out', required=True, type=str)
|
||
|
@click.option('--pdf', required=True, type=str)
|
||
|
def extract(out: str, pdf: str):
|
||
|
params = {
|
||
|
'key': secrets.PDFTABLES_KEY,
|
||
|
'format': 'csv',
|
||
|
}
|
||
|
with open(pdf, 'rb') as f:
|
||
|
files = {
|
||
|
'f': ('file.pdf', f.read()),
|
||
|
}
|
||
|
body = requests.post('https://pdftables.com/api',
|
||
|
params=params,
|
||
|
files=files)
|
||
|
with open(out, 'w') as f:
|
||
|
f.write(body.text)
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
extract()
|