all repos — sunstroke @ master

MyPyload.py (view raw)

 1# My edited version of https://github.com/thammi/pyload-utils/blob/master/pyloadutils/pyload.py
 2import json
 3import requests
 4from urllib.parse import urljoin, urlencode, quote_plus
 5from dotenv import load_dotenv
 6from os import getenv
 7load_dotenv()
 8
 9PYLOAD_HOST = getenv("PYLOAD_HOST") or "http://localhost:8000/"
10PYLOAD_USER = getenv("PYLOAD_USER") or "pyload"
11PYLOAD_PW = getenv("PYLOAD_PW") or "pyload"
12
13PYLOAD_API_URL = PYLOAD_HOST + 'api/'
14PYLOAD_LOGIN_URL = urljoin(PYLOAD_API_URL, 'login')
15PYLOAD_ADDPACKAGE_URL = urljoin(PYLOAD_API_URL, 'add_package')
16
17QUOTES = '"{}"'
18
19class Pyload:
20
21    def __init__(self):
22        login_data = {'username': PYLOAD_USER, 'password': PYLOAD_PW}
23        self.session = requests.Session()
24        self.session.post(PYLOAD_LOGIN_URL, data=login_data)
25
26    def addPackage(self, name: str, links: list, password: str = "", ):
27        #link_string = [quote_plus(x) for x in links]
28        name_string = QUOTES.format(name)
29        link_string = json.dumps(links)
30
31        request_data = { 'name': name_string, 'links': link_string }
32        return self.session.post(url=PYLOAD_ADDPACKAGE_URL, data=request_data)