mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 21:07:59 +00:00
Merge branch 'master' into docs
This commit is contained in:
commit
badc227979
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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:
|
||||
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
pysocks
|
||||
tgcrypto
|
11
setup.py
11
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()
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user