Пример #1
0
def index():
    req = request.get_json()
    bot = TelegramBot()
    bot.parse_webhook_data(req)
    success = bot.action()
    return jsonify(success=success
                   )  # TODO: Success should reflect the success of the reply
Пример #2
0
def index():
    req = request.get_json()
    print(json.dumps(req))
    bot = TelegramBot()
    bot.parse_webhook_data(req)
    success = bot.action()
    return jsonify(success=success) # TODO: Success should reflect the success of the reply  it is important else it will continue to send up message
def index():
    req = request.get_json() 
    bot = TelegramBot()
    bot.parse_webhook_data(req)
    
    if bot.incoming_message_text == '/start':
            message = 'Enter search in format /search "train number"'
            success=bot.send_msg(bot.chat_id,message)
            return jsonify(success=success)

    elif bot.incoming_message_text[0:7]=="/search":
            if bot.incoming_message_text[8:].strip(" ")==False:
                success=bot.send_msg(bot.chat_id,"please enter some text")
                return jsonify(success=success)
            searching_text=bot.incoming_message_text[8:]
            print(searching_text)
            message=""
            response=requests.get(f"https://www.etrainstatus.com/live-status?train_number={searching_text}")
            soup=bs4.BeautifulSoup(response.content, 'lxml')
            result=soup.find(class_='contantprt')
            for li in result.findAll('li'):
                message=message+'\n'+li.text
            #response=requests.get(f"https://api.sumanjay.cf/torrent/?query={searching_text}")
            #for x in response.json()[0:3]:
                #message+=f"'name' : {x['name']} \n age:{x['age']} \n 'magnet' : {x['magnet']} \n\n "
            print(str(message))
            success=bot.send_msg(bot.chat_id,urllib.parse.quote(message))
            return jsonify(success=success)
    else:
            message = "invalid command"
            success=bot.send_msg(bot.chat_id,"Invalid Command")
            return jsonify(success=success) 
def index():
    req = request.get_json() 
    bot = TelegramBot()
    bot.parse_webhook_data(req)
    
    if bot.incoming_message_text == '/start':
            message = '🤙Enter search in format /search "text"🤙'
            success=bot.send_msg(bot.chat_id,message)
            return jsonify(success=success)

    elif bot.incoming_message_text[0:7]=="/search":
            if bot.incoming_message_text[8:].strip(" ")==False:
                success=bot.send_msg(bot.chat_id,"please enter some text")
                return jsonify(success=success)
            searching_text=bot.incoming_message_text[8:]
            print(searching_text)
            message=""
            response=requests.get(f"https://api.sumanjay.cf/torrent/?query={searching_text}")
            for x in response.json()[0:3]:
                message+=f"'name' : {x['name']} \n age:{x['age']} \n 'magnet' : {x['magnet']} \n\n "
            print(str(message))
            success=bot.send_msg(bot.chat_id,urllib.parse.quote(message))
            return jsonify(success=success)
    else:
            message = "invalid command"
            success=bot.send_msg(bot.chat_id,"Invalid Command")
            return jsonify(success=success) 
Пример #5
0
def index():
    req = request.get_json()  #storing the data recieved by telegram server
    bot = TelegramBot()  #creating object of telegramBot class
    bot.parse_webhook_data(
        req)  #parsing the json data recieved by telegram server
    success = bot.action()  #basic reply actions

    #if message recieved from user who is in chat with stranger
    if pairs.get(bot.chat_id):

        #if chat mesasge is leave
        if bot.incoming_message_text == "/leave":

            #alerting users with chat ending message.
            bot.send_msg(pairs.get(bot.chat_id), "Stranger left the chat.")
            bot.send_msg(bot.chat_id, "You left the chat.")

            #removing both users from the paired chat_id's
            x = pairs.get(bot.chat_id)
            del pairs[x]
            del pairs[bot.chat_id]
        else:

            #if it was just normal message then forward to the stranger who is in chat with the user
            bot.forward_message(pairs.get(bot.chat_id))

    #else
    else:

        #if user requests to search
        if bot.incoming_message_text == '/search' and bot.chat_id not in queue:
            bot.send_msg(bot.chat_id, "Searching....")
            #add user to searching queue
            queue.append(bot.chat_id)
        print("queue=", queue)

        #if queue has 2 users then match their pair.
        if (len(queue) == 2):
            pairs[queue[0]] = queue[1]
            pairs[queue[1]] = queue[0]
            bot.send_msg(
                queue[0],
                "Search found,you can now start chatting with stranger.\nSharing of files and images is not allowed.\nThis is just chat.\nuse /leave to leave chat."
            )
            bot.send_msg(
                queue[1],
                "Search found,you can now start chatting with stranger.\nSharing of files and images is not allowed.\nThis is just chat.\nuse /leave to leave chat."
            )
            queue.clear()
        print(pairs)
    return jsonify(success=success
                   )  # TODO: Success should reflect the success of the reply
Пример #6
0
def index():
    req = request.get_json()
    bot = TelegramBot()
    bot.parse_webhook_data(req)
    # success = bot.action()
    message = bot.return_message()
    final_ans = income_message(str(message))
    if (final_ans == 1):
        success = bot.send_message("Real new , You can safely forward")
    else:
        success = bot.send_message("Fake new , kindly report")

    return jsonify(success=success
                   )  # TODO: Success should reflect the success of the reply
Пример #7
0
def index():
    req = request.get_json()
    bot = TelegramBot()
    bot.parse_webhook_data(req)
    success=bot.action()
    return jsonify(success=success)
Пример #8
0
def index():
    req = request.get_json()
    bot = TelegramBot()
    bot.parse_webhook_data(req)

    if bot.incoming_message_text == '/start':
        message = 'Enter IDs in format--> /set seriesid-matchid '
        success = bot.send_msg(bot.chat_id, message)
        return jsonify(success=success)

    elif bot.incoming_message_text[0:4] == "/set":
        if bot.incoming_message_text[5:].strip(" ") == False:
            success = bot.send_msg(bot.chat_id, "please enter some text")
            return jsonify(success=success)

        sid = bot.incoming_message_text[5:12]
        mid = bot.incoming_message_text[13:]
        print(sid, mid)

        r = requests.get(
            'https://hs-consumer-api.espncricinfo.com/v1/pages/match/home?seriesId='
            + sid + '&matchId=' + mid)
        pdata = r.json()
        uid = pdata['content']['recentBallCommentary']['ballComments'][0][
            '_uid']
        while True:
            message = ""
            r = requests.get(
                'https://hs-consumer-api.espncricinfo.com/v1/pages/match/home?seriesId='
                + sid + '&matchId=' + mid)
            pdata = r.json()

            if pdata['content']['recentBallCommentary']['ballComments'][0][
                    '_uid'] != uid:
                message += '\n' + pdata['match']['slug']
                message += '\n' + pdata['match']['statusText']
                message += '\n' + 'Innings : ' + str(
                    pdata['match']['liveInning'])

                if (pdata['match']['teams'][0]['inningNumbers'][0] ==
                        pdata['match']['liveInning']):
                    message += '\n' + pdata['match']['teams'][0]['team'][
                        'abbreviation']
                else:
                    message += '\n' + pdata['match']['teams'][1]['team'][
                        'abbreviation']
                message += '\n' + str(pdata['content']['recentBallCommentary']
                                      ['ballComments'][0]['oversActual'])

                if (pdata['content']['recentBallCommentary']['ballComments'][0]
                    ['wides'] != 0):
                    message += '\n' + 'WIDE'
                elif (pdata['content']['recentBallCommentary']['ballComments']
                      [0]['noballs'] != 0):
                    message += '\n' + 'NO-BALL'

                if (pdata['match']['status'] == 'RESULT'):
                    message += '\n' + pdata['match']['statusText']
                elif (pdata['content']['recentBallCommentary']['ballComments']
                      [0]['totalRuns'] == 4):
                    message += '\n' + 'FOUR!!'
                elif (pdata['content']['recentBallCommentary']['ballComments']
                      [0]['totalRuns'] == 6):
                    message += '\n' + 'SIX!!!'
                elif (pdata['content']['recentBallCommentary']['ballComments']
                      [0]['totalRuns'] > 0
                      and pdata['content']['recentBallCommentary']
                      ['ballComments'][0]['totalRuns'] < 4):
                    message += '\n' + str(
                        pdata['content']['recentBallCommentary']
                        ['ballComments'][0]['totalRuns']) + ' Runs!!'
                elif (pdata['content']['recentBallCommentary']['ballComments']
                      [0]['dismissalType'] != None):
                    message += '\n' + 'WICKET!!!'
                    print(pdata['content']['recentBallCommentary']
                          ['ballComments'][0]['dismissalText']['commentary'])
                elif (pdata['content']['recentBallCommentary']['ballComments']
                      [0]['totalRuns'] == 0):
                    message += '\n' + 'DOT!!!'
                uid = pdata['content']['recentBallCommentary']['ballComments'][
                    0]['_uid']

                print(str(message))
                success = bot.send_msg(bot.chat_id,
                                       urllib.parse.quote(message))
                time.sleep(2)
                return jsonify(success=success)

    else:
        message = "invalid command"
        success = bot.send_msg(bot.chat_id, "Invalid Command")
        return jsonify(success=success)