Skip to content

Instantly share code, notes, and snippets.

@Kiruha01
Last active January 21, 2023 07:18
Show Gist options
  • Save Kiruha01/26cb35e93dedbccbb7100834ba538da6 to your computer and use it in GitHub Desktop.
Save Kiruha01/26cb35e93dedbccbb7100834ba538da6 to your computer and use it in GitHub Desktop.
Promocodes

Promocodes

Установка зависимостей

Открой в терминале эту папку и введи

pip install -r requirements.txt

Инструкция

Открой файл config.yml и введи данные:

phone: +79953807118 # твой телефон
chat_id: 1800022801 # id канала, откуда нужно брать информацию


api_id: 26945647 # app_id приложения Telegram
api_hash: 9486e4af73bd75ba054ffaca6791f1b7 # api_hash приложения Telegram

Как получить id канала?

Введи в файл config.yml свой телефон и запусти файл fetch_chat_ids.py. В этой папке создасться файлик chats.txt, где будут перечислены все твои каналы и из id. Выбери нужный и вставь id в файл конфигурации.

После этого открой сайт с промокодами и запусти файл main.py.

Сначала скрипт попросит тебя навести мышь на поле ввода промокода

Наведи мышь на поле ввода и нажми Enter...

После на кнопку

Наведи мышь на кнопку и нажми Enter...

Далее скрипт несколько раз попрыгает мышкой чтобы ты убедился, что все правильно настроено. Если нет - закрой и открой скрипт main.py заново.

Ну вот и всё! теперь каждые 5 секунд скрипт будет проверять промокод и вставлять его в поле ввода.

phone: +79953807118
chat_id: 1800022801
api_id: 26945647
api_hash: 9486e4af73bd75ba054ffaca6791f1b7
from telethon.sync import TelegramClient
from telethon.errors import SessionPasswordNeededError
import yaml
with open('config.yml', 'r') as file:
# Load the YAML data into a dictionary
config = yaml.load(file, Loader=yaml.FullLoader)
# Replace YOUR_API_ID and YOUR_API_HASH with your own values
api_id = config['api_id']
api_hash = config['api_hash']
phone = config['phone']
chat_id = config['chat_id']
# Replace YOUR_PHONE_NUMBER with your phone number
client = TelegramClient('session_name', api_id, api_hash).start(phone=phone)
def main():
try:
client.connect()
if not client.is_user_authorized():
client.send_code_request(phone)
client.sign_in(phone, input('Enter the code: '))
except SessionPasswordNeededError:
client.sign_in(password=input('2FA Password: '))
with open("chats.txt", "w", encoding='utf-8') as file:
for i in client.get_dialogs():
file.write(f"{i.name} - {i.entity.id}\n")
main()
import re
import time
from typing import Tuple
import pyautogui as pyautogui
import yaml
from telethon.sync import TelegramClient
from telethon.errors import SessionPasswordNeededError
from telethon.tl.types import PeerChannel
INPUT_POSITION = (0, 0)
BUTTON_POSITION = (0, 0)
# Replace YOUR_API_ID and YOUR_API_HASH with your own values
with open('config.yml', 'r') as file:
# Load the YAML data into a dictionary
config = yaml.load(file, Loader=yaml.FullLoader)
# Replace YOUR_API_ID and YOUR_API_HASH with your own values
api_id = config['api_id']
api_hash = config['api_hash']
phone = config['phone']
chat_id = config['chat_id']
# Replace YOUR_PHONE_NUMBER with your phone number
client = TelegramClient('session_name', api_id, api_hash).start(phone=phone)
client.start()
def move_and_click(position: Tuple[int, int]) -> None:
pyautogui.moveTo(position)
pyautogui.click()
def prepare():
global INPUT_POSITION
global BUTTON_POSITION
input("Наведи мышь на поле ввода и нажми Enter...")
INPUT_POSITION = pyautogui.position()
input("Наведи мышь на кнопку и нажми Enter...")
BUTTON_POSITION = pyautogui.position()
print("Проверка...")
for _ in range(4):
pyautogui.moveTo(INPUT_POSITION)
time.sleep(0.2)
pyautogui.moveTo(BUTTON_POSITION)
time.sleep(0.2)
def main():
try:
client.connect()
if not client.is_user_authorized():
client.send_code_request(phone)
client.sign_in(phone, input('Enter the code: '))
except SessionPasswordNeededError:
client.sign_in(password=input('2FA Password: '))
# Replace CHANNEL_NAME with the name of the channel you want to parse
channel = client.get_entity(PeerChannel(int(chat_id)))
# Get the ID of the last message that was processed
last_message_id = 0
while True:
# Get the messages that have been sent after the last message that was processed
messages = client.get_messages(channel, min_id=last_message_id)
for message in messages:
# Use regular expressions or other string manipulation techniques to extract the news from the message text
code = re.search(r'Промо: ([A-Z0-9\-]*)', message.text)
if code:
# found promocode
move_and_click(INPUT_POSITION)
pyautogui.write(code.group(1))
move_and_click(BUTTON_POSITION)
print(code.group(1))
last_message_id = message.id
# Sleep for 5 seconds before polling again
time.sleep(5)
prepare()
main()
MouseInfo==0.1.3
pyaes==1.6.1
pyasn1==0.4.8
PyAutoGUI==0.9.53
PyGetWindow==0.0.9
PyMsgBox==1.0.9
pyperclip==1.8.2
PyRect==0.2.0
PyScreeze==0.1.28
pytweening==1.0.4
PyYAML==6.0
rsa==4.9
Telethon==1.26.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment