Created
September 8, 2016 01:21
-
-
Save univerio/06d2f10a9f5a5dfe2ff246389bc0e1d8 to your computer and use it in GitHub Desktop.
Batch check downloader for PrismHR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from datetime import datetime | |
import time | |
import requests | |
import click | |
HOST = "https://seqee.prismhr.com" | |
JSESSIONID = "-----REDACTED-----" # get these values from your cookies | |
ESSauthToken = "-----REDACTED-----" | |
COOKIES = {"JSESSIONID": JSESSIONID, "ESSauthToken": ESSauthToken} | |
def download(key, filename=None): | |
if filename is None: | |
filename = "{}.pdf".format(key) | |
click.echo("Downloading {} to {}...".format(key, filename)) | |
resp = requests.get("{}/seq/stream".format(HOST), params={"key": key}, | |
cookies=COOKIES, stream=True) | |
assert resp.headers["Content-Type"] == "application/pdf" | |
with open(filename, "wb") as f: | |
for chunk in resp.iter_content(chunk_size=1024): | |
if chunk: | |
f.write(chunk) | |
def fetch_one(id): | |
click.echo("Building {}...".format(id)) | |
while True: | |
resp = requests.post( | |
"{}/seq/cmd/call".format(HOST), | |
data={"method_name": "checkprint", "voucher_number": id}, | |
cookies=COOKIES) | |
d = resp.json() | |
click.echo("Status: {}".format(d["status"])) | |
if d["status"] == "DONE": | |
return d["key"] | |
time.sleep(5) | |
def fetch_list(year): | |
resp = requests.post("{}/seq/cmd/call".format(HOST), | |
data={"method_name": "checkhistory", "year": year}, | |
cookies=COOKIES) | |
d = resp.json() | |
header, *rows = d["check_list"] | |
checks = [dict(zip(header, row)) for row in rows] | |
return checks | |
ids = [check["voucher_number"] for check in checks] | |
return ids | |
@click.command() | |
@click.argument("year", type=int, default=datetime.now().year) | |
def main(year): | |
checks = fetch_list(year) | |
for check in checks: | |
i = check["voucher_number"] | |
key = fetch_one(i) | |
check_date = datetime.strptime(check["pay_date"], "%m/%d/%Y").date() | |
download(key, filename="{}.pdf".format(check_date.isoformat())) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment