-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdfpart.py
More file actions
34 lines (23 loc) · 878 Bytes
/
pdfpart.py
File metadata and controls
34 lines (23 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import pdftables_api, requests
import os
# https://pdftables.com/pdf-to-excel-api
API_KEY = os.getenv('API_KEY')
convertor = pdftables_api.Client(API_KEY)
def remaining_conversions():
req = requests.get(f'https://pdftables.com/api/remaining?key={API_KEY}')
return f'{int(req.text)} pages available to convert'
def make_same_fileName(file_name):
splited_path = file_name.split('/')
primar_name = splited_path[-1]
splited_primar = primar_name.split('.')
if 'pdf' not in splited_primar:
raise ValueError("file extension must be pdf")
return splited_primar[0] + '.xlsx'
def convert_pdf_to_xlsl(pdf_path, xlsx_path):
name = make_same_fileName(pdf_path)
final_path = xlsx_path + name
convertor.xlsx(pdf_path, final_path)
print(f'Done. For this api_key remains {remaining_conversions()}')
return name
if __name__ == '__main__':
print(remaining_conversions())