From 585855a8728f87cc5383329bd227f6d6ba840aff Mon Sep 17 00:00:00 2001 From: Andronaco Marco Date: Wed, 12 Jul 2023 13:02:46 +0200 Subject: working version --- main.py | 63 ++++++++++++++++++++------------------------------------------- 1 file changed, 20 insertions(+), 43 deletions(-) (limited to 'main.py') 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()) -- cgit 1.4.1-2-gfad0 0514a6a9b93af7858a3db1467091f80df'>blame)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
[ui]
splash=true
intype=true
beep=false
statuses.muc=all
theme=boothj5
history=true
titlebar=true
mouse=false
flash=false
vercheck=false
statuses.console=all
statuses.chat=all

[connection]
autoping=60
reconnect=5
account=me@server.org

[chatstates]
enabled=true
outtype=false
gone=10

[notifications]
remind=60
invite=true
sub=true
message=true
room=mention
message.current=true
room.current=true
typing=true
typing.current=false
message.text=true
room.text=true

[alias]
friends=/who online friends
bob=/msg bob@server.org hey wassup?

[logging]
chlog=true
grlog=true
maxsize=1048580
rotate=true
shared=true

[otr]
warn=true
log=redact
policy=manual

[presence]
autoaway.mode=away
autoaway.time=15
autoaway.message=Away from computer
autoaway.check=true