コード例 #1
0
async def send_new_posts():
    load_sent_ids()
    print('\n\nloaded')
    print(sent_ids)
    print('\n\n')

    p = Piazza()
    p.user_login("email", "pass")

    user_status = p.get_user_status()
    nid = user_status['networks'][0]['id']

    eecs2030 = p.network(nid)
    feed = eecs2030.get_feed(limit=99999)

    feed_arr = feed['feed']
    piazzaobj_arr = []

    for post in feed_arr:
        full_post = eecs2030.get_post(post['id'])
        latest_update = full_post['history'][0]
        piazzaobj_arr.append(
            PiazzaObject(post['id'], latest_update['subject'],
                         latest_update['content'], full_post['created'],
                         'https://piazza.com/class?cid=' + post['id']))

    print(sent_ids)
    for piazzaobj in piazzaobj_arr:
        if not piazzaobj.id in sent_ids:
            print(f'sending {piazzaobj.id}')
            await send_post(piazzaobj)
            sent_ids.append(piazzaobj.id)

    save_sent_ids()
コード例 #2
0
def main():

    parser = argparse.ArgumentParser(description='Process user input for piazza queries')
    parser.add_argument('-q', '--query', nargs="+")
    parser.add_argument('-t', '--tags', nargs="+") 
    parser.add_argument('-r', '--range', nargs=2)
    parser.add_argument('-i', '--instructor-only', action='store_true')
    parser.add_argument('-p', '--posts', action='store_true')
    parser.add_argument('-l', '--force-login', action='store_true')
    args = parser.parse_args()

    if (args.query is None): 
        raise(InputError("Query not given!"))

    queryObj = QueryObj()
    queryObj.add_query(args.query)
    queryObj.add_tags(args.tags)
    queryObj.add_time_range(args.range)
    queryObj.bool_inst_notes(args.instructor_only)
    queryObj.bool_pinned(args.posts)

    loginfile = os.path.expanduser("~") + "/.pizza"
    
    if not args.force_login: 
        try: 
            pkl = pickle.load(open(loginfile,"rb"))
            data = {'email', pkl['email'], 'password': pkl['password'].decode('rot13')}
        except IOError:
            email = raw_input('Piazza Email: ')
            password = getpass.getpass()
            data = {'email': email, 'password': password}
            pkl = {'email': email, 'password': password.encode('rot13')}
            pickle.dump(pkl, open(loginfile, "wb"))

    piazza = Piazza() 
    piazza.user_login(data['email'], data['password'])
    user_status = piazza.get_user_status()
    
    classes = user_status['networks']
    classes = sorted(classes, key=lambda k: k['status'])
    # list classes 
    print("Choose a Class")
    counter = 1
    for c in classes: 
        info = c['name']
        if c['status'] == 'inactive':
            info = '(inactive) ' + info
        print '{0:2d}: {1:s}'.format(counter, info)
        counter = counter + 1