Skip to content

Instantly share code, notes, and snippets.

@deathping1994
Created February 2, 2017 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deathping1994/b54870fc6b252eda5a516d8422cd697c to your computer and use it in GitHub Desktop.
Save deathping1994/b54870fc6b252eda5a516d8422cd697c to your computer and use it in GitHub Desktop.
import time
import redis
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import requests
from PIL import Image
r = redis.StrictRedis(db=2)
messages = [{
"txt":"/newgame",
},
{
"btn":"btn reply_markup_button",
"index":0
},
{
"btn":"btn reply_markup_button",
"index":0
},
{
"btn":"btn reply_markup_button",
"index":0
},
{
"prev": "Please enter a title for the game.",
"act":"name"
},
{
"prev": "Please enter a short description of the game.",
"act":"description"
},
{
"prev": "Please upload a photo, 640x360 pixels.",
"act":"brick"
},
{
"prev": "Now upload a demo GIF or send /empty to skip this step.",
"txt":"/empty"
},
{
"act":"code"
}
]
driver = webdriver.Chrome()
def wait(web_opening_time=3):
time.sleep(web_opening_time)
def web_driver_quit():
driver.quit()
def telegram_login():
driver.get('https://web.telegram.org/')
def open_botfather():
driver.get('https://web.telegram.org/#/im?p=@BotFather')
def click_button(btn):
button = None
while button is None:
try:
button = driver.find_element_by_xpath("//button[@class='%s']" % btn)
except:
pass
button.click()
import re
import random
def registerNewGame():
web_obj = driver.find_element_by_xpath("//div[@contenteditable='true']")
re = requests.get("https://pub.gamezop.com/v2/games?id=S1lEkd3YZx")
games = re.json()['games']
for game in games:
for msg in messages:
if 'txt' in msg:
web_obj.send_keys(msg['txt'])
web_obj.send_keys(Keys.RETURN)
elif 'btn' in msg:
click_button(msg['btn'])
elif 'act' in msg:
if msg['act'] == "brick":
im = Image.open(requests.get(game['brick'], stream=True).raw)
im = im.resize((640, 360), Image.BILINEAR)
im.save(os.path.join(os.getcwd(), game['code']+".png"))
image_btn = driver.find_element_by_xpath("//input[@class='im_media_attach_input']")
image_btn.send_keys(os.path.join(os.getcwd(), game['code']+".png"))
elif msg['act'] == "gif":
if os.path.exists(os.path.join(os.getcwd(), game['code']+".gif")):
image_btn = driver.find_element_by_xpath("//input[@class='im_media_attach_input']")
image_btn.send_keys(os.path.join(os.getcwd(), game['code']+".gif"))
elif msg['act'] == "code":
id = r.get(game['code'])
if id is None:
exit(1)
web_obj.send_keys('gzp_'+str(id))
web_obj.send_keys(Keys.RETURN)
else:
web_obj.send_keys(game[msg['act']])
web_obj.send_keys(Keys.RETURN)
wait(random.randrange(10,50,1))
wait(random.randrange(100,500,1))
def download_images():
re = requests.get("https://pub.gamezop.com/v2/games?id=S1lEkd3YZx")
games = re.json()['games']
games = games[0:10]
for game in games:
for msg in messages:
if 'act' in msg:
if msg['act'] == "brick":
im = Image.open(requests.get(game['brick'], stream=True).raw)
im = im.resize((640, 360), Image.BILINEAR)
im.save(os.path.join(os.getcwd(), game['code'] + ".png"))
if __name__ == "__main__":
# download_images()
telegram_login()
x = input("1 to proceed")
if x != 1:
exit(0)
open_botfather()
registerNewGame()
wait(30)
web_driver_quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment