예제 #1
0
def bunk_lecture(n, tot_lec, chatID):
    init_db()
    record = db_session.query(Attendance).filter(
        Attendance.chatID == chatID).first()
    attended = record.total_lec_attended
    conducted = record.total_lec_conducted
    result = (((int(attended) + int(tot_lec)) - int(n)) /
              (int(conducted) + tot_lec)) * 100
    return round(result, 2)  #Round up to 2 decimals.
예제 #2
0
def until80(chatID):
    init_db()
    record = db_session.query(Attendance).filter(
        Attendance.chatID == chatID).first()
    attended = record.total_lec_attended
    conducted = record.total_lec_conducted
    x = Symbol('x')
    expr = Eq((((int(attended) + x) / (int(conducted) + x)) * 100), 80)
    soln = solveset(expr, x)
    return next(iter(soln))  # Extracting the integer from singleton set soln.
예제 #3
0
def until80(chatID):
    """
    Calculates the no. of lectures user must attend in order to get overall attendance to 80%

    Parameters:
    chatID -- user's unique 9-digit ChatID from telegram
    """
    init_db()
    subject_data = Lecture.query.filter(
        and_(Lecture.chatID == chatID, Lecture.name == "Total")).first()
    attended = subject_data.attended
    conducted = subject_data.conducted
    x = Symbol('x')
    expr = Eq((((int(attended) + x) / (int(conducted) + x)) * 100), 80)
    soln = solveset(expr, x)
    return next(iter(soln))  # Extracting the integer from singleton set soln.
예제 #4
0
def register(bot, update, user_data):
    """
    Let all users register with their credentials.
    Similar to start() but this function can be invoked by /register command.

    If user's chatID & DOB are already present in database then ends the conversation.
    Otherwise, if only chatID is present, then stores PID(StudentID) in user_data dict &
    gives control to parent_login() function.

    If both conditions are false, then asks user to input Student details (PID & Password)
    and gives control to credentials()
    """
    init_db()
    if Chat.query.filter(Chat.chatID == update.message.chat_id).first():
        if Chat.query.filter(
                and_(Chat.chatID == update.message.chat_id,
                     Chat.DOB != None)).first():
            messageContent = "Already registered!"
            bot.sendMessage(chat_id=update.message.chat_id,
                            text=messageContent)
            return ConversationHandler.END

        student_data = Chat.query.filter(
            Chat.chatID == update.message.chat_id).first()
        user_data['Student_ID'] = student_data.PID

        messageContent = textwrap.dedent("""
        Now enter your Date of Birth (DOB) in the following format:
        `DD/MM/YYYY`
        """)
        update.message.reply_text(messageContent, parse_mode='markdown')
        return PARENT_LGN

    messageContent = textwrap.dedent("""
    Okay, send me your MIS credentials in this format:
    `Student-ID password`
    (in a single line, separated by a space)

    Use /cancel to abort.
    """)
    bot.sendMessage(chat_id=update.message.chat_id,
                    text=messageContent,
                    parse_mode='markdown')
    return CREDENTIALS
예제 #5
0
    def process_item(self, item, spider):
        #Initiate DB
        init_db()

        if not Attendance.query.filter(
                Attendance.chatID == spider.chatID).first():
            record = Attendance(
                total_lec_attended=item['total_lec_attended'],
                total_lec_conducted=item['total_lec_conducted'],
                chatID=spider.chatID)
            db_session.add(record)
            db_session.commit()
        else:
            db_session.query(Attendance).filter(Attendance.chatID == spider.chatID).\
            update({'total_lec_attended': item['total_lec_attended'],
                    'total_lec_conducted':item['total_lec_conducted']})
            db_session.commit()

        return item
예제 #6
0
def main():
    """Start the bot and use long polling to detect and respond to new messages."""
    # Init Database
    init_db()
    dispatcher = updater.dispatcher

    conv_handler = ConversationHandler(
        entry_points=[
            CommandHandler('start', start),
            CommandHandler('register', register)
        ],
        states={CREDENTIALS: [MessageHandler(Filters.text, credentials)]},
        fallbacks=[CommandHandler('cancel', cancel)])
    # Handlers
    start_handler = CommandHandler('start', start)
    attendance_handler = CommandHandler('attendance',
                                        fetch_attendance,
                                        pass_job_queue=True)
    results_handler = CommandHandler('results',
                                     fetch_results,
                                     pass_job_queue=True)
    bunk_handler = CommandHandler('bunk', bunk_lec, pass_args=True)
    eighty_handler = CommandHandler('until80', until_eighty)
    delete_handler = CommandHandler('delete', delete)
    help_handler = CommandHandler('help', help)
    tips_handler = CommandHandler('tips', tips)
    unknown_message = MessageHandler(Filters.text, unknown)

    # Dispatchers
    dispatcher.add_handler(conv_handler)
    dispatcher.add_handler(delete_handler)
    dispatcher.add_handler(attendance_handler)
    dispatcher.add_handler(results_handler)
    dispatcher.add_handler(bunk_handler)
    dispatcher.add_handler(eighty_handler)
    dispatcher.add_handler(help_handler)
    dispatcher.add_handler(tips_handler)
    dispatcher.add_handler(unknown_message)

    #Long polling
    updater.start_polling(clean=True)
    updater.idle()
예제 #7
0
def bunk_lecture(n, tot_lec, chatID, stype, index):
    """
    Bunk calculator.

    Parameters:
    n       -- no. of lectures for a subject to bunk
    tot_lec -- total lectures conducted for that subject
    chatID  -- user's unique 9-digit ChatID from telegram
    stype   -- Lectures or Practicals
    index   -- Index of the user-selected subject from list of subjects
    """
    init_db()
    if (stype == "Lectures"):
        subject_data = Lecture.query.filter(Lecture.chatID == chatID).all()
    else:
        subject_data = Practical.query.filter(Practical.chatID == chatID).all()
    index -= 1  # DB Tables are Zero-Index
    attended = subject_data[index].attended
    conducted = subject_data[index].conducted

    result = (((int(attended) + int(tot_lec)) - int(n)) /
              (int(conducted) + tot_lec)) * 100
    return round(result, 2)  #Round up to 2 decimals.
예제 #8
0
def main():
    """Start the bot and use webhook to detect and respond to new messages."""
    init_db()
    dispatcher = updater.dispatcher

    # Handlers
    conv_handler = ConversationHandler(
        entry_points=[
            CommandHandler('start', start),
            CommandHandler('register', register, pass_user_data=True)
        ],
        states={
            CREDENTIALS:
            [MessageHandler(Filters.text, credentials, pass_user_data=True)],
            PARENT_LGN:
            [MessageHandler(Filters.text, parent_login, pass_user_data=True)]
        },
        fallbacks=[CommandHandler('cancel', cancel)])

    bunk_handler = ConversationHandler(
        entry_points=[CommandHandler('bunk', bunk)],
        states={
            CHOOSING: [
                MessageHandler(Filters.text | Filters.command,
                               bunk_choose,
                               pass_user_data=True)
            ],
            INPUT:
            [MessageHandler(Filters.text, bunk_input, pass_user_data=True)],
            CALCULATING: [
                MessageHandler(Filters.text | Filters.command,
                               bunk_calc,
                               pass_user_data=True)
            ]
        },
        fallbacks=[CommandHandler('cancel', cancel)])

    attendance_target_handler = ConversationHandler(
        entry_points=[CommandHandler('target', attendance_target)],
        states={
            SELECT_YN: [MessageHandler(Filters.text, select_yn)],
            INPUT_TARGET: [MessageHandler(Filters.text, input_target)]
        },
        fallbacks=[CommandHandler('cancel', cancel)])

    edit_attendance_target_handler = ConversationHandler(
        entry_points=[CommandHandler('edit_target', edit_attendance_target)],
        states={
            UPDATE_TARGET:
            [MessageHandler(Filters.text | Filters.command, update_target)],
        },
        fallbacks=[CommandHandler('cancel', cancel)])

    push_notification_handler = ConversationHandler(
        entry_points=[CommandHandler('push', push_notification)],
        states={
            NOTIF_MESSAGE: [
                MessageHandler(Filters.text,
                               notification_message,
                               pass_user_data=True)
            ],
            NOTIF_CONFIRM: [
                MessageHandler(Filters.text,
                               notification_confirm,
                               pass_user_data=True)
            ],
        },
        fallbacks=[CommandHandler('cancel', cancel)])

    delete_notification_handler = ConversationHandler(
        entry_points=[CommandHandler('revert', revert_notification)],
        states={
            ASK_UUID:
            [MessageHandler(Filters.text, ask_uuid, pass_user_data=True)],
            CONFIRM_REVERT: [
                MessageHandler(Filters.text | Filters.command,
                               confirm_revert,
                               pass_user_data=True)
            ],
        },
        fallbacks=[CommandHandler('cancel', cancel)])

    clean_records_handler = CommandHandler('clean',
                                           clean_all_attendance_records)

    attendance_handler = CommandHandler('attendance', attendance)
    results_handler = CommandHandler('results', results)
    itinerary_handler = CommandHandler('itinerary', itinerary, pass_args=True)
    profile_handler = CommandHandler('profile', profile)
    eighty_handler = CommandHandler('until80', until_eighty)
    until_handler = CommandHandler('until', until, pass_args=True)
    delete_handler = CommandHandler('delete', delete)
    help_handler = CommandHandler('help', help_text)
    tips_handler = CommandHandler('tips', tips)
    unknown_message = MessageHandler(Filters.text | Filters.command, unknown)

    # Dispatchers
    dispatcher.add_handler(conv_handler)
    dispatcher.add_handler(delete_handler)
    dispatcher.add_handler(attendance_handler)
    dispatcher.add_handler(results_handler)
    dispatcher.add_handler(profile_handler)
    dispatcher.add_handler(itinerary_handler)
    dispatcher.add_handler(bunk_handler)
    dispatcher.add_handler(eighty_handler)
    dispatcher.add_handler(until_handler)
    dispatcher.add_handler(attendance_target_handler)
    dispatcher.add_handler(edit_attendance_target_handler)
    dispatcher.add_handler(help_handler)
    dispatcher.add_handler(tips_handler)
    dispatcher.add_handler(push_notification_handler)
    dispatcher.add_handler(delete_notification_handler)
    dispatcher.add_handler(clean_records_handler)
    dispatcher.add_handler(unknown_message)

    if DEBUG:
        updater.start_polling(clean=True)
        updater.idle()
    else:
        webhook_url = 'https://{0}:8443/{1}'.format(os.environ['URL'], TOKEN)
        updater.start_webhook(listen='0.0.0.0',
                              port=8443,
                              url_path=TOKEN,
                              key='files/private.key',
                              cert='files/cert.pem',
                              webhook_url=webhook_url,
                              clean=True)
        updater.idle()
예제 #9
0
def main():
    """Start the bot and use webhook to detect and respond to new messages."""
    init_db()
    dispatcher = updater.dispatcher

    conv_handler = ConversationHandler(
        entry_points=[
            CommandHandler('start', start),
            CommandHandler('register', register, pass_user_data=True)
        ],
        states={
            CREDENTIALS:
            [MessageHandler(Filters.text, credentials, pass_user_data=True)],
            PARENT_LGN:
            [MessageHandler(Filters.text, parent_login, pass_user_data=True)]
        },
        fallbacks=[CommandHandler('cancel', cancel)])

    bunk_handler = ConversationHandler(
        entry_points=[CommandHandler('bunk', bunk)],
        states={
            CHOOSING: [
                MessageHandler(Filters.text | Filters.command,
                               bunk_choose,
                               pass_user_data=True)
            ],
            INPUT: [
                MessageHandler(Filters.command | Filters.command,
                               bunk_input,
                               pass_user_data=True)
            ],
            CALCULATING: [
                MessageHandler(Filters.text | Filters.command,
                               bunk_calc,
                               pass_user_data=True)
            ]
        },
        fallbacks=[CommandHandler('cancel', cancel)])

    # Handlers
    attendance_handler = CommandHandler('attendance',
                                        fetch_attendance,
                                        pass_job_queue=True)
    results_handler = CommandHandler('results',
                                     fetch_results,
                                     pass_job_queue=True)
    itinerary_handler = CommandHandler('itinerary', itinerary, pass_args=True)
    eighty_handler = CommandHandler('until80', until_eighty)
    delete_handler = CommandHandler('delete', delete)
    help_handler = CommandHandler('help', help_text)
    tips_handler = CommandHandler('tips', tips)
    unknown_message = MessageHandler(Filters.text | Filters.command, unknown)

    # Dispatchers
    dispatcher.add_handler(conv_handler)
    dispatcher.add_handler(delete_handler)
    dispatcher.add_handler(attendance_handler)
    dispatcher.add_handler(results_handler)
    dispatcher.add_handler(itinerary_handler)
    dispatcher.add_handler(bunk_handler)
    dispatcher.add_handler(eighty_handler)
    dispatcher.add_handler(help_handler)
    dispatcher.add_handler(tips_handler)
    dispatcher.add_handler(unknown_message)

    webhook_url = 'https://%s:8443/%s' % (os.environ['URL'], TOKEN)

    updater.start_webhook(listen='0.0.0.0',
                          port=8443,
                          url_path=TOKEN,
                          key='files/private.key',
                          cert='files/cert.pem',
                          webhook_url=webhook_url,
                          clean=True)
    updater.idle()
예제 #10
0
from scraper.scrapers import AmazonScraper, PaycomScraper
import scraper.data_utils
from scraper.database import init_db, db_session, rowInsert
from datetime import datetime, timedelta
import pandas as pd
import logging
from dotenv import load_dotenv

load_dotenv()

#create tables/set up base for ORM
init_db()
from scraper.models import Test, Employees, ScheduleRecon

logging.basicConfig(filename='pladlog.log',format='%(asctime)s - %(levelname)s - %(message)s', datefmt='%d-%b-%y %H:%M:%S', level=logging.INFO)
logging.captureWarnings(True)


fromDate = datetime.today().strftime('%Y-%m-%d')
toDate = (datetime.today() + timedelta(days=7)).strftime('%Y-%m-%d')


AMZL = AmazonScraper(f'https://logistics.amazon.com/scheduling/home/api/v2/rosters?fromDate={fromDate}&serviceAreaId=6f0c423f-f609-4e32-a7f1-e624143b9d49&toDate={toDate}')
# PAY = PaycomScraper('https://www.paycomonline.net/v4/cl/web.php/scheduling/api/manage-schedules/employee?skip=0&take=100&q=&filterInstanceId=f1f61f69ac734e5c81c3027684388a&filterName=cl-manage-scheds',\
#                         f'https://www.paycomonline.net/v4/cl/web.php/scheduling/api/manage-schedules/employee-shift?startDate={fromDate}&endDate={toDate}&skip=0&take=500&q=&filterInstanceId=52766f934b3d48d8a1df9db39eb537&filterName=cl-manage-scheds&scheduleGroupCode=2237')


try:
    if AMZL.authorize():
        amzlReservationsdf = pd.DataFrame(AMZL.getReservations())
        amzlReservationsdf.to_csv('amzn_reservations.csv')
예제 #11
0
 def test_parse_html(self):
     init_db()
     scraper = IronManScraper()
     scraper.get_athletes()
     db_session.remove()