diff --git a/MANIFEST.in b/MANIFEST.in index 168fb020..f818e13a 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,5 @@ ## Include -include COPYING COPYING.lesser NOTICE +include COPYING COPYING.lesser NOTICE requirements.txt recursive-include compiler *.py *.tl *.tsv *.txt ## Exclude diff --git a/examples/README.md b/examples/README.md index 545516fa..6b14e3e5 100644 --- a/examples/README.md +++ b/examples/README.md @@ -2,8 +2,9 @@ This folder contains example scripts to show you how **Pyrogram** looks like. You can start with [hello_world.py](https://github.com/pyrogram/pyrogram/blob/master/examples/hello_world.py) and continue -with the more advanced examples. Every script is working right away, meaning you can simply copy-paste and run, the only things -you have to change are the target chats (username, id) and file paths for sending media (photo, video, ...). +with the more advanced examples. Every script is working right away (provided you correctly set up your credentials), meaning +you can simply copy-paste and run, the only things you have to change are the target chats (username, id) and file paths for +sending media (photo, video, ...). - [**hello_world.py**](https://github.com/pyrogram/pyrogram/blob/master/examples/hello_world.py) - [**get_history.py**](https://github.com/pyrogram/pyrogram/blob/master/examples/get_history.py) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 0c3bdb1d..a86a4c97 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -29,7 +29,6 @@ import struct import tempfile import threading import time -from collections import namedtuple from configparser import ConfigParser from datetime import datetime from hashlib import sha256, md5 @@ -59,8 +58,20 @@ from .style import Markdown, HTML log = logging.getLogger(__name__) -ApiKey = namedtuple("ApiKey", ["api_id", "api_hash"]) -Proxy = namedtuple("Proxy", ["enabled", "hostname", "port", "username", "password"]) + +class APIKey: + def __init__(self, api_id: int, api_hash: str): + self.api_id = api_id + self.api_hash = api_hash + + +class Proxy: + def __init__(self, enabled: bool, hostname: str, port: int, username: str, password: str): + self.enabled = enabled + self.hostname = hostname + self.port = port + self.username = username + self.password = password class Client: @@ -127,7 +138,7 @@ class Client: def __init__(self, session_name: str, - api_key: tuple or ApiKey = None, + api_key: tuple or APIKey = None, proxy: dict or Proxy = None, test_mode: bool = False, token: str = None, @@ -790,18 +801,28 @@ class Client: parser = ConfigParser() parser.read("config.ini") - if parser.has_section("pyrogram"): - self.api_key = ApiKey( + if self.api_key is not None: + self.api_key = APIKey( + api_id=int(self.api_key[0]), + api_hash=self.api_key[1] + ) + elif parser.has_section("pyrogram"): + self.api_key = APIKey( api_id=parser.getint("pyrogram", "api_id"), api_hash=parser.get("pyrogram", "api_hash") ) else: - self.api_key = ApiKey( - api_id=int(self.api_key[0]), - api_hash=self.api_key[1] - ) + raise AttributeError("No API Key found") - if parser.has_section("proxy"): + if self.proxy is not None: + self.proxy = Proxy( + enabled=True, + hostname=self.proxy["hostname"], + port=int(self.proxy["port"]), + username=self.proxy.get("username", None), + password=self.proxy.get("password", None) + ) + elif parser.has_section("proxy"): self.proxy = Proxy( enabled=parser.getboolean("proxy", "enabled"), hostname=parser.get("proxy", "hostname"), @@ -809,15 +830,6 @@ class Client: username=parser.get("proxy", "username", fallback=None) or None, password=parser.get("proxy", "password", fallback=None) or None ) - else: - if self.proxy is not None: - self.proxy = Proxy( - enabled=True, - hostname=self.proxy["hostname"], - port=int(self.proxy["port"]), - username=self.proxy.get("username", None), - password=self.proxy.get("password", None) - ) def load_session(self, session_name): try: diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..21c697f1 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +pysocks +tgcrypto \ No newline at end of file diff --git a/setup.py b/setup.py index 9c0068c6..64cc7f2d 100644 --- a/setup.py +++ b/setup.py @@ -24,6 +24,12 @@ from setuptools import setup, find_packages from compiler.api import compiler as api_compiler from compiler.error import compiler as error_compiler + +def requirements(): + with open("requirements.txt", encoding="utf-8") as r: + return [i.strip() for i in r] + + if len(argv) > 1 and argv[1] != "sdist": api_compiler.start() error_compiler.start() @@ -76,8 +82,5 @@ setup( python_requires="~=3.4", packages=find_packages(exclude=["compiler*"]), zip_safe=False, - install_requires=[ - "pysocks", - "tgcrypto" - ] + install_requires=requirements() )