2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 05:18:10 +00:00

Merge branch 'master' into docs

This commit is contained in:
Dan 2018-03-22 18:07:23 +01:00
commit badc227979
5 changed files with 45 additions and 27 deletions

View File

@ -1,5 +1,5 @@
## Include ## Include
include COPYING COPYING.lesser NOTICE include COPYING COPYING.lesser NOTICE requirements.txt
recursive-include compiler *.py *.tl *.tsv *.txt recursive-include compiler *.py *.tl *.tsv *.txt
## Exclude ## Exclude

View File

@ -2,8 +2,9 @@
This folder contains example scripts to show you how **Pyrogram** looks like. 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 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 with the more advanced examples. Every script is working right away (provided you correctly set up your credentials), meaning
you have to change are the target chats (username, id) and file paths for sending media (photo, video, ...). 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) - [**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) - [**get_history.py**](https://github.com/pyrogram/pyrogram/blob/master/examples/get_history.py)

View File

@ -29,7 +29,6 @@ import struct
import tempfile import tempfile
import threading import threading
import time import time
from collections import namedtuple
from configparser import ConfigParser from configparser import ConfigParser
from datetime import datetime from datetime import datetime
from hashlib import sha256, md5 from hashlib import sha256, md5
@ -59,8 +58,20 @@ from .style import Markdown, HTML
log = logging.getLogger(__name__) 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: class Client:
@ -127,7 +138,7 @@ class Client:
def __init__(self, def __init__(self,
session_name: str, session_name: str,
api_key: tuple or ApiKey = None, api_key: tuple or APIKey = None,
proxy: dict or Proxy = None, proxy: dict or Proxy = None,
test_mode: bool = False, test_mode: bool = False,
token: str = None, token: str = None,
@ -790,18 +801,28 @@ class Client:
parser = ConfigParser() parser = ConfigParser()
parser.read("config.ini") parser.read("config.ini")
if parser.has_section("pyrogram"): if self.api_key is not None:
self.api_key = ApiKey( 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_id=parser.getint("pyrogram", "api_id"),
api_hash=parser.get("pyrogram", "api_hash") api_hash=parser.get("pyrogram", "api_hash")
) )
else: else:
self.api_key = ApiKey( raise AttributeError("No API Key found")
api_id=int(self.api_key[0]),
api_hash=self.api_key[1]
)
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( self.proxy = Proxy(
enabled=parser.getboolean("proxy", "enabled"), enabled=parser.getboolean("proxy", "enabled"),
hostname=parser.get("proxy", "hostname"), hostname=parser.get("proxy", "hostname"),
@ -809,15 +830,6 @@ class Client:
username=parser.get("proxy", "username", fallback=None) or None, username=parser.get("proxy", "username", fallback=None) or None,
password=parser.get("proxy", "password", 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): def load_session(self, session_name):
try: try:

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
pysocks
tgcrypto

View File

@ -24,6 +24,12 @@ from setuptools import setup, find_packages
from compiler.api import compiler as api_compiler from compiler.api import compiler as api_compiler
from compiler.error import compiler as error_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": if len(argv) > 1 and argv[1] != "sdist":
api_compiler.start() api_compiler.start()
error_compiler.start() error_compiler.start()
@ -76,8 +82,5 @@ setup(
python_requires="~=3.4", python_requires="~=3.4",
packages=find_packages(exclude=["compiler*"]), packages=find_packages(exclude=["compiler*"]),
zip_safe=False, zip_safe=False,
install_requires=[ install_requires=requirements()
"pysocks",
"tgcrypto"
]
) )