예제 #1
0
args = parser.parse_args()

if not config.TOKEN:
    print("No TOKEN found in config")
    args.console = True

if args.console:
    print("Running in console mode")

if not args.console:
    methods.startupMessage(args.console)
    atexit.register(methods.shutdownMessage)

server_retry = config.SERVER_RETRY_TIMEOUT
while True:
    methods.alarms(args.console)

    #print("Make request: {0}".format(last_update_id))
    try:
        if args.console:

            i, o, e = select.select([sys.stdin], [], [], config.TIMEOUT)
            result = {}
            result["ok"] = True
            if i:
                entry = {
                    "message": {
                        "text": sys.stdin.readline().strip(),
                        "chat": {
                            "id": 0
                        }
#!/usr/bin/env python3
import requests
import config
import methods
import atexit
import time

last_update_id = 0

methods.startupMessage()
atexit.register(methods.shutdownMessage)

server_retry = config.SERVER_RETRY_TIMEOUT
while True:
    methods.alarms()

    #print("Make request: {0}".format(last_update_id))
    try:
        r = requests.post( config.API_URL + "getUpdates"
                         , json={ "offset" : last_update_id + 1
                                , "timeout" : config.TIMEOUT
                                }
                         , timeout=config.TIMEOUT + 5
                         )
        result = r.json()

        if result["ok"]:
            limit = 10
            for update in result["result"]:
                limit-=1
                if limit <= 0: break
예제 #3
0
#!/usr/bin/env python3
import requests
import config
import methods
import atexit

last_update_id = 0

methods.startupMessage()
atexit.register(methods.shutdownMessage)

while True:
    methods.alarms()

    # print("Make request: {0}".format(last_update_id))
    r = requests.post(
        config.API_URL + "getUpdates",
        json={"offset": last_update_id + 1, "timeout": config.TIMEOUT},
        timeout=config.TIMEOUT + 5,
    )
    result = r.json()

    if result["ok"]:
        for update in result["result"]:
            update_id = update["update_id"]
            if update_id > last_update_id:
                last_update_id = update_id

            methods.processMessage(update["message"])
    else:
        # TODO error handling