コード例 #1
0
def addTracking(bot, update, args, chat=None):
    if len(args) < 1:
        bot.reply(update, "Use /sub username1 username2 username3 ...")
        return
    amazonItems = args
    not_found = []
    already_subscribed = []
    successfully_subscribed = []

    tg_user = update.message.chat_id
    if User.select().where(User.telegramId == tg_user).count() == 0:
        User.create(telegramId=tg_user)

    userdb = User.select().where(User.telegramId == tg_user).get()

    for item in amazonItems:
        Tracking.create(user=userdb.id, asin=item, status='active')

    reply = "OK"

    if len(not_found) is not 0:
        reply += "Sorry, I didn't find username{} {}\n\n".format(
            "" if len(not_found) is 1 else "s", ", ".join(not_found))

    if len(already_subscribed) is not 0:
        reply += "You're already subscribed to {}\n\n".format(
            ", ".join(already_subscribed))

    if len(successfully_subscribed) is not 0:
        reply += "I've added your subscription to {}".format(
            ", ".join(successfully_subscribed))

    bot.send_message(chat_id=update.message.chat_id, text=reply)
コード例 #2
0
def cmd_sub(bot, update, args, chat=None):
    if len(args) < 1:
        bot.reply(update, "Use /sub username1 username2 username3 ...")
        return
    tw_usernames = args
    not_found = []
    already_subscribed = []
    successfully_subscribed = []

    for tw_username in tw_usernames:
        tw_user = bot.get_tw_user(tw_username)

        if tw_user is None:
            not_found.append(tw_username)
            continue

        if Tracking.select().where(Tracking.tw_user == tw_user,
                                   Tracking.tg_chat == chat).count() == 1:
            already_subscribed.append(tw_user.full_name)
            continue

        Tracking.create(tg_chat=chat, tw_user=tw_user)
        successfully_subscribed.append(tw_user.full_name)

    reply = ""

    if len(not_found) is not 0:
        reply += "Sorry, I didn't find username{} {}\n\n".format(
            "" if len(not_found) is 1 else "s", ", ".join(not_found))

    if len(already_subscribed) is not 0:
        reply += "You're already subscribed to {}\n\n".format(
            ", ".join(already_subscribed))

    if len(successfully_subscribed) is not 0:
        reply += "I've added your subscription to {}".format(
            ", ".join(successfully_subscribed))

    bot.reply(update, reply)
コード例 #3
0
ファイル: tracker.py プロジェクト: dhamaniasad/orangetrack
login_page = browser.get('http://183.177.124.6/24online/webpages/myaccountlogin.jsp')

login_form = login_page.soup.select('form')[0]

login_form.select('[name="username"]')[0]['value'] = ''
login_form.select('[name="password"]')[0]['value'] = ''

page2 = browser.submit(login_form, login_page.url)

remaining_data = page2.soup.select('#datausagediv1 > table > tr > td > font')[-1].text

package_expiry = page2.soup.select('td.inputtd > font')
package_expiry_date = datetime.datetime.strptime(package_expiry[5].text, '%d/%m/%Y %H:%M')
remaining_data

add_data = Tracking.create(remaining_data=remaining_data.strip('MBmbKGkg'))
add_data.save()

expires_in = package_expiry_date - datetime.datetime.now()
print "Expires in {} days".format(expires_in.days)
data_in_gb = round(float(remaining_data.strip('GMKBgmkb'))/1024, 2)
print "{}, or {} GB of data remaining".format(remaining_data, data_in_gb)

today = datetime.date.today()

last_30_days = arrow.now().replace(days=-30).naive


query = Tracking.select().where(Tracking.added_time >= last_30_days).order_by(Tracking.added_time.asc())

first_day = list(query)[0]