Advertisement
Guest User

Untitled

a guest
Apr 30th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.54 KB | None | 0 0
  1. import requests, re
  2. from time import sleep as wait
  3. import pymysql.cursors
  4.  
  5. connection = pymysql.connect(host='localhost',
  6.                              user='root',
  7.                              password='',
  8.                              db='job-cash',
  9.                              charset='utf8mb4',
  10.                              cursorclass=pymysql.cursors.DictCursor)
  11.  
  12.  
  13. def checkdb(loc, player, player2):
  14.     with connection.cursor() as cursor:
  15.         mycursor = connection.cursor()
  16.         sql = "SELECT * FROM tennis WHERE Player_1 = %s"
  17.         adr = (player)
  18.         mycursor.execute(sql, adr)
  19.         print(mycursor.rowcount)
  20.         if not mycursor.rowcount:
  21.             cursor = connection.cursor()
  22.             sql = "SELECT * FROM tennis "
  23.             cursor.execute(sql)
  24.             oneRow = cursor.fetchone()
  25.             print("Row Result: ", oneRow)
  26.             cursor = connection.cursor()
  27.             sql = "Insert into tennis (Location, Player_1, Player_2) " \
  28.                   + " values (%s, %s, %s) "
  29.             cursor.execute(sql, (loc, player, player2))
  30.             connection.commit()
  31.  
  32.  
  33. url = 'https://mobvhj.xyz/LiveFeed/Mb_BestGamesExtZip'
  34. data = {
  35.     'count': 1000,
  36.     'country': 2,
  37.     'grMode': 3
  38. }
  39. request = requests.Session()
  40. info = request.get(url, params=data)
  41. games = info.json()['Value']
  42. num = 1
  43. while num < 10:
  44.     for game in games:
  45.         if ('SC' in game) and ('COP' in game['SC']):
  46.             try:
  47.                 if 'Гейм' in game['SC']['COP']:
  48.                     print(game['L'], game['MIO']['Loc'], game['MIO']['TSt'])
  49.                     print(game['O1'], 'vs.', game['O2'])
  50.                     gg = re.split(r'\|', game['SC']['COP'])
  51.                     gg.remove('')
  52.                     print(gg)
  53.                     if gg[0].split()[-1] != '40':
  54.                         text = 'Внимание поступил сигнал!' + "\n" + game['L'] + game['MIO']['Loc'] + game['MIO'][
  55.                             'TSt'] + '\n' + game['O1'] + 'vs.' + game['O2'] + '\n' + 'Следующий гейм 40:40 - нет'
  56.                         #r = requests.get(
  57.                          #   'https://api.telegram.org/bot710029530:AAEWIhpzU74kzxfEesjk6hOv9mItxdd8xLE/sendmessage?chat_id=460960819&text=' + text)
  58.                         checkdb(game['L'], game['O1'], game['O2'])
  59.                         wait(30)
  60.                         print('отправил')
  61.                     print('\n')
  62.             except Exception as err:
  63.                 #print(err)
  64.                 pass
  65.     wait(2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement