diff options
author | Andronaco Marco <marco.andronaco@olivetti.com> | 2023-07-12 13:02:46 +0200 |
---|---|---|
committer | Andronaco Marco <marco.andronaco@olivetti.com> | 2023-07-12 13:02:46 +0200 |
commit | 585855a8728f87cc5383329bd227f6d6ba840aff (patch) | |
tree | 634aa7868a614e45eeab6772a2a5ddf367e74a91 /main.py | |
parent | 733a0a23988fb074c93e6c398d8b9142ee180b29 (diff) | |
download | sunstroke-585855a8728f87cc5383329bd227f6d6ba840aff.tar.gz |
working version
Diffstat (limited to 'main.py')
-rw-r--r-- | main.py | 63 |
1 files changed, 20 insertions, 43 deletions
diff --git a/main.py b/main.py index 53502c8..d7fb9c9 100644 --- a/main.py +++ b/main.py @@ -1,48 +1,25 @@ -import json -import requests # https://github.com/pyload/pyload/wiki/module.Api.Api -from Sole import get_sole, remove_first +from Overpost import get_newspaper +from MyPyload import Pyload +from os import getenv -SESSION_FILENAME = "session.txt" -PYLOAD_PROTOCOL = "http" -PYLOAD_HOST = "localhost" -PYLOAD_PORT = 8000 -PYLOAD_USER = "pyload" -PYLOAD_PW = "pyload" -PYLOAD_API_ENDPOINT = "/api" -PYLOAD_LOGIN_ENDPOINT = "/login" -PYLOAD_ADDPACKAGE_ENDPOINT = "/generateAndAddPackages" -PYLOAD_API_URL = f"{ PYLOAD_PROTOCOL }://{ PYLOAD_HOST }:{ PYLOAD_PORT }{ PYLOAD_API_ENDPOINT }" +NEWSPAPER_PREFIX = getenv("NEWSPAPER_PREFIX") or "" -LOGIN_DATA = { "username": PYLOAD_USER, "password": PYLOAD_PW } -LOGIN_URL = PYLOAD_API_URL + PYLOAD_LOGIN_ENDPOINT -ADDPACKAGE_URL = PYLOAD_API_URL + PYLOAD_ADDPACKAGE_ENDPOINT +def scroll_dict(dictionary): + i = 0 + for key, values in dictionary.items(): + if i >= len(values): + i = 0 + yield key, values[i] + i += 1 -def get_session_id(): - try: - with open(SESSION_FILENAME, "r", encoding="utf-8") as in_file: - return in_file.readline() - except FileNotFoundError: - res = requests.post(LOGIN_URL, data=LOGIN_DATA) - cookies = res.cookies.get_dict() - session_id = cookies['pyload_session'] - with open(SESSION_FILENAME, "w", encoding="utf-8") as out_file: - out_file.write(session_id) - return session_id - -def add_package(links): - ADDPACKAGE_DATA = { "links": json.dumps(links), "session": session_id } - print(ADDPACKAGE_URL) - print(ADDPACKAGE_DATA) - kek = requests.post(ADDPACKAGE_URL, data=LOGIN_DATA).text - return kek +def download_link(connection, name, link): + return connection.addPackage(name=name, links=[link]) + +def main(): + newspapers = get_newspaper(NEWSPAPER_PREFIX, 0) # 0 -> today + con = Pyload() + pids = [ download_link(con, NEWSPAPER_PREFIX, link) for _, link in scroll_dict(newspapers) ] + print(pids) if __name__ == "__main__": - session_id = get_session_id() - - #sole = get_sole() - #sole_link = remove_first(sole)[1][0] - - - links = [ "http://localhost:8080/file2", "http://localhost:8080/file1" ] - - print(add_package(links)) + exit(main()) |