Use ydotool to just type it into a web field
This commit is contained in:
parent
36413aafd0
commit
456f9007b1
39
invoice.py
39
invoice.py
@ -12,8 +12,9 @@ import glob
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import requests
|
import subprocess
|
||||||
import textwrap
|
import textwrap
|
||||||
|
import time
|
||||||
|
|
||||||
# Config globals
|
# Config globals
|
||||||
rate = float(41.00)
|
rate = float(41.00)
|
||||||
@ -41,38 +42,12 @@ with open(csv[0], 'r') as csv:
|
|||||||
|
|
||||||
timesheet[date][issue] += hours
|
timesheet[date][issue] += hours
|
||||||
|
|
||||||
# Next, construct args for the request we'll make to invoice-generator.com's API
|
|
||||||
requestbody = {
|
|
||||||
"from": "JACOB",
|
|
||||||
"to": "CLIENT",
|
|
||||||
"number": 9999,
|
|
||||||
"date": "CURRENT_DATE",
|
|
||||||
"due_date": "DUE_DATE",
|
|
||||||
"terms": "Net 14 days",
|
|
||||||
"items": []
|
|
||||||
}
|
|
||||||
for k,v in timesheet.items():
|
for k,v in timesheet.items():
|
||||||
print(k)
|
print(k)
|
||||||
for i,h in v.items():
|
for i,h in v.items():
|
||||||
requestbody["items"].append({
|
|
||||||
"name": f"{ k } - { i }",
|
|
||||||
"quantity": h,
|
|
||||||
"unit_cost": rate
|
|
||||||
})
|
|
||||||
print(f' { i } - { h }')
|
print(f' { i } - { h }')
|
||||||
|
# Now actually do the work
|
||||||
# Submit said request
|
subprocess.run(["ydotool", "type", f"{k} - {i}\t{round(h,2)}\t{rate}\t"])
|
||||||
resp = requests.post(
|
time.sleep(0.10)
|
||||||
url = 'https://invoice-generator.com',
|
subprocess.run(["ydotool", "type", "\n"])
|
||||||
json = json.dumps(requestbody),
|
time.sleep(0.10)
|
||||||
headers = {
|
|
||||||
"Authorization": f"Bearer { os.environ['INVOICE_GENERATOR_APIKEY'] }"
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
if not resp.status_code == 200:
|
|
||||||
print(resp)
|
|
||||||
quit()
|
|
||||||
|
|
||||||
with open('out.pdf', 'w') as f:
|
|
||||||
f.write(resp.text)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user