示例#1
0
def reply(activity, bot, data):
    state = State()
    result = state.getStudent(activity["sender"]["id"])
    scraper = Scraper()
    if result:
        rollno = str(result['RollNumber'])
        wak = str(result['wak'])
        #Find the exam Code.
        #BT3R15NOV17
        current = "BT" + convert(str(result["Semester"])) + "R15" + "NOV18"
        print(current)
        try:
            subjects, cred, gpa = scraper.getResults(rollno, wak)
        except Exception:
            bot.send_text_activity(activity, "Not Yet! Hold your horses.")
            return
        response = ""
        for i in subjects:
            for j in i:
                response += j
                response += "\t"
            response += "\n"
        bot.send_text_activity(activity, response)
        bot.send_text_activity(activity, "Total Credits: " + str(cred))
        bot.send_text_activity(activity, "Gpa: " + str(gpa))
    else:
        bot.send_text_activity(
            activity,
            "Authentication failed. Please message your rollno and web access key again."
        )
        bot.send_text_activity(
            activity,
            "Enter roll no. and web access key seperated by a single space.")
示例#2
0
def reply(activity, bot, data):
    print(data.get_entities())
    credentials = activity["message"]["text"].split(" ")
    rollno = credentials[0]
    wak = credentials[1]
    if len(wak) > 5:
        bot.send_text_activity(
            activity, "Please check your roll no. and web access key again.")
        bot.send_text_activity(
            activity,
            "Enter roll no. and web access key seperated by a single space.")
        return
    scraper = Scraper()
    scraper.authenticate(rollno, wak)
    if scraper.authenticated:
        student = Student()
        student_data = {}
        student_data["user_id"] = activity["sender"]["id"]
        student_data["wak"] = wak
        student_data["student_id"] = rollno
        student.insert_or_update_data(student_data)
        bot.send_text_activity(activity, "Authentication Successful!")
    else:
        bot.send_text_activity(
            activity, "Please check your roll no. and web access key again.")
        bot.send_text_activity(
            activity,
            "Enter roll no. and web access key seperated by a single space.")
示例#3
0
def reply(activity, bot, data):
    student = Student()
    result = student.get_data(activity["sender"]["id"])
    scraper = Scraper()
    if result:
        rollno = str(result['student_id'])
        wak = str(result['wak'])
        scraper.authenticate(rollno, wak)
        attendance = scraper.get_attendance()
        reply = "Your attendance % is " + str(attendance)
        bot.send_text_activity(activity, reply)
        if attendance == 100:
            responses = [
                "Are you insane?! 😮 Take a break dude!",
                "Someone needs to take a day off. 😒"
            ]
        elif attendance > 95:
            responses = [
                "Your parents must be so proud of you. 🤗",
                "You do love your college a bit too much, Don't you think? 🤔",
                "What are you? A book worm? 😏", "Ghar me rahne nahi dete kya?"
            ]
        elif attendance > 85:
            responses = [
                "Perfectly balanced. As all things should be. 😉",
                "Good Going! 😁"
            ]
        elif attendance > 80:
            responses = [
                "You're certainly someone who can balance work and life. 👍",
                "Making the best of both worlds huh? 😎"
            ]
        elif attendance > 75:
            responses = [
                "Phew! Someone likes to live on the edge. 😳",
                "I see you've been bunking a lot of classes lately. 🤨 Be cautious and attend your classes.",
                "The kind of balance you have stricken, seems to me as if you are a part time tightrope walker at a circus"
            ]
        elif attendance > 65:
            responses = [
                "Keep the condonation money handy mate. 😬",
                "You should go to your classes if you don't want to burn a hole in your pocket. 😕",
                "Ghar me rahne nahi dete kya?"
            ]
        else:
            responses = [
                "Looks like you've been too lazy for your own good. 😴",
                "I hope your okay with sitting amongst your juniors next year. 🤭"
            ]
        reply = random.choice(responses)
        bot.send_text_activity(activity, reply)
    else:
        bot.send_text_activity(
            activity,
            "Authentication failed. Please message your roll no. and web access key again."
        )
        bot.send_text_activity(
            activity,
            "Enter roll no. and web access key seperated by a single space.")
示例#4
0
async def reply(activity, bot, data):
    query = Query()
    db = TinyDB('./db.json')
    result = db.search(query.userid == activity.from_property.id)
    scraper = Scraper()
    if len(result) > 0:
        result = result[0]
        rollno = str(result['rollno'])
        wak = str(result['wak'])
        scraper.authenticate(rollno, wak)
        attendance = scraper.get_attendance()
        reply = "Your attendance % is " + str(attendance)
        await bot.send_text_activity(activity, reply)
        if attendance == 100:
            responses = [
                "Are you insane?! 😮 Take a break dude!",
                "Someone needs to take a day off. 😒"
            ]
        elif attendance > 95:
            responses = [
                "Your parents must be so proud of you. 🤗",
                "You do love your college a bit too much, Don't you think? 🤔",
                "What are you? A book worm? 😏"
            ]
        elif attendance > 85:
            responses = [
                "Perfectly balanced. As all things should be. 😉",
                "Good Going! 😁"
            ]
        elif attendance > 80:
            responses = [
                "You're certainly someone who can balance work and life. 👍",
                "Making the best of both worlds huh? 😎"
            ]
        elif attendance > 75:
            responses = [
                "Phew! Someone likes to live on the edge. 😳",
                "I see you've been bunking a lot of classes lately. 🤨 Be cautious and attend your classes."
            ]
        elif attendance > 65:
            responses = [
                "Keep the condonation money handy mate. 😬",
                "You should go to your classes if you don't want to burn a hole in your pocket. 😕"
            ]
        else:
            responses = [
                "Looks like you've been too lazy for your own good. 😴",
                "I hope your okay with sitting amongst your juniors next year. 🤭"
            ]
        reply = random.choice(responses)
        await bot.send_text_activity(activity, reply)
    else:
        await bot.send_text_activity(
            activity,
            "Authentication failed. Please message your roll no. and web access key again."
        )
        await bot.send_text_activity(
            activity,
            "Enter roll no. and web access key seperated by a single space.")
示例#5
0
def reply(activity, bot, data):
    student = Student()
    result = student.get_data(activity["sender"]["id"])
    scraper = Scraper()
    if result:
        rollno = str(result['student_id'])
        wak = str(result['wak'])
        scraper.authenticate(rollno, wak)
        conducted, attended = scraper.getPeriods()
        percentageifpresent = round(((attended+7)/(conducted + 7) * 100), 2)
        percentageifabsent = round(((attended)/(conducted + 7) * 100), 2)
        response = "Your attendance will be %.2f if present, otherwise %.2f" % (percentageifpresent, percentageifabsent)
        bot.send_text_activity(activity, response)
        if percentageifabsent > 95:
            responses = [
                "Go ahead and take a break, You deserve it. 🤗",
                "Seriously, take a day off. 😒",
                "You've been regular to the college. You've earned a day for yourselves. 👍"
            ]
        elif percentageifabsent > 90:
            responses = [
                "Well, your attendance % will still be quite good. But it's upto you. 😊",
                "You are very much eligible to skip college tomorrow. 😁",
                "You can skip college without any guilt. 😏"
            ]
        elif percentageifabsent > 85:
            responses = [
                "It is probably okay to skip college tomorrow. Exercise some caution though. 🙂",
                "You've been doing great. Try to keep it up... or just stay back for once. 😅",
                "Aaj Jaane Ki Zidd Naa Karo.. 😝"
            ]
        elif percentageifabsent > 80:
            responses = [
                "I'd tell you to go to the class par meri kaun sunta hai? 🙄",
                "If you think you can manage 75%, you are more than welcome to try. 😬",
                "\"Laziness may seem attractive, but work gives satisfaction.\" - Anne Frank 😇" 
            ]
        elif percentageifabsent > 75:
            responses = [
                "I see you like to live dangerously ☠... But give a little thought to it.",
                "You can probably get away with this one. 😈",
                "You've been skipping college way too much but you just might get another day."
            ]
        elif percentageifabsent > 65:
            responses = [
                "Please just get off your butt and go to the class. 😒",
                "I know the bed looks very cozy right now but you should definitely go. 😐",
                "Your laziness is really not worth paying that extra money to the college. 😔"
            ]
        else:
            responses = [
                "Beta tumse naa ho paayega 😐",
                "I'm sorry but you probably can't afford to take even a single day off. 🤐",
                "Uhmm.. No way you can skip college right now. 😑"
            ]
        reply = random.choice(responses)
        bot.send_text_activity(activity, reply)
示例#6
0
def parse_inner_page(html): 
    """
    Parser para paginas interiores
    :param html:
    :return:
    """
    s1 = Scraper(html)
    parsed_dict = {
        'titulo': s1.soup.find('title').text.encode("utf-8"),
        'zona': s1.scrape_tags_with_class('p', 'zona-nombre'),
        'precio': s1.scrape_tags_with_class('p', 'precio-final'),
        'telefono': s1.scrape_tags_with_class('span', 'lineInmo'),
        'info': s1.scrape_tags_with_class('div', 'dotInfo'),
        'referencia': s1.find_tag_or_empty('div', 'class', 'referencia-slider'),
        'descripcion': s1.find_tag_and_strip_html('div', 'id', 'descripcion'),
        'anunciante': s1.find_tag_or_empty('p', 'id', 'nombre-inmobiliaria'),
    }
    # Intenta recuperar valores del string
    info = parsed_dict['info']
    parsed_dict['garajes'] = find_in_separated_string(info, '|', ['garaje'])
    parsed_dict['banos'] = find_in_separated_string(info, '|', ['baño'])
    parsed_dict['recamaras'] = find_in_separated_string(info, '|', ['Amb', 'recamara'])
    parsed_dict['metros'] = find_in_separated_string(info, '|', ['m²'])

    return parsed_dict
示例#7
0
def parse_main_page(html):
    """
    Parser para la pagina principal
    :param html:
    :return:
    """
    s2 = Scraper(html)
    parsed_dict = {
        'target_urls': s2.get_attr_from_tag_with_class('a', 'class', 'holder-link')
    }
    return parsed_dict
示例#8
0
def reply(activity, bot, data):
    student = Student()
    result = student.get_data(activity["sender"]["id"])
    scraper = Scraper()
    if result:
        print(result)
        rollno = str(result['student_id'])
        wak = str(result['wak'])
        #Find the exam Code.
        #BT3R15NOV17
        current = "BT" + get_semester_from_id(result['student_id']) + "R15" + "NOV18"
        print(current)
        try:
            subjects, cred, gpa = scraper.getResults(rollno,wak,current)
        except Exception:
            bot.send_text_activity(activity, "Not Yet! Hold your horses.")
            return
        response = ""
        for i in subjects:
            for j in i:
                response += j
                response += "\t"
            response += "\n"
        bot.send_text_activity(activity, response)
        bot.send_text_activity(activity, "Total Credits: " + str(cred))
        bot.send_text_activity(activity, "Gpa: " + str(gpa))
        
        if gpa >= 9.5:
            responses = ["iamgonnacry", "really", "hurtmyfeelings", "Clapping", "telugu1"]
        elif gpa >= 9.0:
            responses = ["Winner", "genius", "mindblown", "youaretheman", "awesomesauce", "minions", "badass", "proud", "meeru", "mahesh"]
        elif gpa >= 8.0:
            responses = ["Woah", "whosawesome", "WOW", "fantastic", "Mogambo", "superabba", "intelli"]
        elif gpa >= 7.0:
            responses = ["goodjob", "groot", "betterluck", "deserve", "control"]
        elif gpa >= 6.0:
            responses = ["barelysurviving", "sarsarle", "apnatimeaayega"]
        elif gpa >= 5.0:
            responses = ["iknowthatfeel", "iknowtfeel", "baymax", "nextsem", "rightinthefeels"]
        elif gpa >= 4.0:
            responses = ["doyouthink", "laughing", "howamisupposedtolive", "tearsineyes", "doomed", "feels", "subject"]
        elif gpa < 4.0:
            responses = ["ohdear", "mkalaadla", "gfather", "hug", "crying", "ritf", "balayya"]
        reply = random.choice(responses)
        bot.send_rich_activity(activity, "https://www.utorai.com/assets/gifs/" + reply + ".gif")
    else:
        bot.send_text_activity(activity, "Authentication failed. Please message your rollno and web access key again.")
        bot.send_text_activity(activity, "Enter roll no. and web access key seperated by a single space.")
示例#9
0
def reply(activity, bot, data):
    query = Query()
    db = TinyDB('./db.json')
    result = db.search(query.userid == activity["sender"]["id"])
    scraper = Scraper()
    if len(result) > 0:
        result = result[0]
        rollno = str(result['rollno'])
        wak = str(result['wak'])
        scraper.authenticate(rollno, wak)
        entities = data.get_entities()
        if 'semester' in entities:
            gpa = scraper.get_gpa(entities['semester'])
            reply = "Your SGPA is " + str(gpa)
        else:
            gpa = scraper.get_cgpa()
            reply = "Your CGPA is " + str(gpa)
        bot.send_text_activity(activity, reply)
        if gpa > 9.5:
            responses = [
                "Woah! Look at you going all out on your tests! Awesome! 💯",
                "Watch out! We've got a badass over here. 😎"
            ]
        elif gpa > 9.0:
            responses = [
                "Are you sure you aren't Einstein? 🧐 Keep up the good work! 👍",
                "If maintaining your grades up was an art, You'd be the Picasso of it. 😏"
            ]
        elif gpa > 8.0:
            responses = [
                "We've got a champ here! You are doing great! 👏",
                "Seems like you’ve got what it takes to make it to the top. 😉"
            ]
        elif gpa > 7.0:
            responses = [
                "Hang in there bud! You're on the right track! ✌",
                "You'd probably think it's enough but hey, a little hard work never killed anyone. 😊"
            ]
        elif gpa > 6.0:
            responses = [
                "Who needs a good CGPA when you're cool no? 😎 JK, you still need it.. 😅",
                "You are hanging by a thread here bud. But it's never too late though. 🙂"
            ]
        else:
            responses = [
                "It's okay, you don't have to be a topper!  The only one you have to beat is the one you were last semester. Work harder this time! 😉",
                "Don't get disheartened yet. There's a lot to look forward to, if you make sure you study harder. 😇",
                "\"If at first you don't succeed, then skydiving isn't for you.\" - Steven Wright 😊"
            ]
        reply = random.choice(responses)
        bot.send_text_activity(activity, reply)
    else:
        bot.send_text_activity(
            activity,
            "Authentication failed. Please message your rollno and web access key again."
        )
        bot.send_text_activity(
            activity,
            "Enter roll no. and web access key seperated by a single space.")
示例#10
0
async def reply(activity, bot, data):
    print(data.get_entities())
    credentials = activity.text.split(" ")
    rollno = credentials[0]
    wak = credentials[1]
    if len(wak) > 5:
        await bot.send_text_activity(
            activity, "Please check your roll no. and web access key again.")
        await bot.send_text_activity(
            activity,
            "Enter roll no. and web access key seperated by a single space.")
        return
    scraper = Scraper()
    scraper.authenticate(rollno, wak)
    if scraper.authenticated:
        query = Query()
        db = TinyDB('./db.json')
        result = db.search(query.userid == activity.from_property.id)
        if len(result) > 0:
            db.update({
                'rollno': rollno,
                'wak': wak
            }, query.userid == activity.from_property.id)
            await bot.send_text_activity(activity,
                                         "Authentication Successful!")
        else:
            db.insert({
                'userid': activity.from_property.id,
                'rollno': rollno,
                'wak': wak
            })
            await bot.send_text_activity(activity,
                                         "Authentication Successful!")
    else:
        await bot.send_text_activity(
            activity, "Please check your roll no. and web access key again.")
        await bot.send_text_activity(
            activity,
            "Enter roll no. and web access key seperated by a single space.")