Skip to content

Instantly share code, notes, and snippets.

@squaresmile
Last active September 14, 2020 22:02
Show Gist options
  • Save squaresmile/5cd12a71d2bb3e318250351b72e9cbab to your computer and use it in GitHub Desktop.
Save squaresmile/5cd12a71d2bb3e318250351b72e9cbab to your computer and use it in GitHub Desktop.
#!/data/data/com.termux/files/usr/bin/env python
import platform
from pathlib import Path
import httpx
NAME = "Cereal"
BASE_PATH = "/data/data/com.termux/files/home/storage/pictures/"
TO_BE_UPLOADED_FOLDER = "Screenshots"
SUBMITED_FOLDER = "Submitted"
EVENT_ID = "20200914"
NODES_URL = f"https://submissions.atlasacademy.io/event/{EVENT_ID}"
PARSER_URL = "https://submissions.atlasacademy.io/submit/screenshot"
START_TIME = 1600084000
LOG_FILE = "logs.txt"
# PARSER_URL = "https://httpbin.org/post"
if platform.uname().system == "Windows":
base_path = Path().resolve()
else:
base_path = Path(BASE_PATH).resolve()
screenshots = base_path / TO_BE_UPLOADED_FOLDER
submitted = base_path / SUBMITED_FOLDER
submitted.mkdir(parents=False, exist_ok=True)
log = base_path / LOG_FILE
if not log.exists():
with open(log, "w", encoding="utf-8") as fp:
fp.write("filename,receipt\n")
def main() -> None:
event_info = httpx.get(NODES_URL)
nodes_info = event_info.json()["nodes"]
nodes_map = {i: node for i, node in zip(range(len(nodes_info)), nodes_info)}
for index, node in nodes_map.items():
print(f"{index}: {node['name']}")
choice = input("Select quest: ")
if choice.isdigit() and int(choice) in nodes_map:
chosen_node = nodes_map[int(choice)]
print(f"{chosen_node['name']} chosen")
post_data = {
"event_uid": chosen_node["event_uid"],
"event_node_uid": chosen_node["uid"],
"submitter": NAME,
"type": "full",
}
images = [
screenshot
for screenshot in screenshots.iterdir()
if screenshot.suffix.lower() in (".jpg", ".png")
and screenshot.stat().st_mtime > START_TIME
]
images = sorted(images, key=lambda x: x.stat().st_mtime)
with open(log, "a", encoding="utf-8") as f:
for image in images:
fh = image.open("rb")
files = {"files[]": (image.name, fh)}
r = httpx.post(PARSER_URL, data=post_data, files=files)
print(f"{image.name}: {r.status_code}: {r.text}")
if r.json()["status"] == "Success":
for receipt in r.json()["receipts"]:
f.write(f"{receipt['filename']},{receipt['receipt']}\n")
fh.close()
image.replace(submitted / image.name)
input("Press Enter to exit...")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment