Ejemplo n.º 1
0
def search(search_term, page_num=1, per_page=50):
    url = "http://api.mendeley.com/oapi/documents/search/"
    data = {'title':'title',
            'journal':'publication_outlet',
            'authors':'authors',
            'doi':'doi',
            'uri':'mendeley_url'}
    query_args = {'page':page_num,
                  'items':per_page,
                  'consumer_key':settings.MENDELEY_CONSUMER_KEY}

    encoded_args = urllib.urlencode(query_args)
    url = url + urllib2.quote(search_term) + '?'
    headers = { 'User-Agent' : 'Mozilla/5.0' }

    req = urllib2.Request(url + encoded_args, headers=headers)

    try:
      json_results = urllib2.urlopen(req)
    except urllib2.HTTPError:
      return []

    results = json.load(json_results)

    results = results['documents']

    return [change_keys(data, result) for result in results]
Ejemplo n.º 2
0
def _format(entry):
    data = {'title':'title',
            'journal':'arxiv_journal_ref',
            'authors':'authors',
            'doi':'arxiv_doi',
            'uri':'id'}
    result = change_keys(data, entry)
    result['authors'] = [author['name'] for author in result['authors']]
    return result
Ejemplo n.º 3
0
def search(search_term, page_num=1, per_page=50):
    url = "http://www.citeulike.org/json/search/all?"
    data = {'title':'title',
            'journal':'journal',
            'authors':'authors',
            'doi':'doi',
            'uri':'href'}
    query_args = {'q': search_term, 'page':page_num, 'per_page':per_page}

    encoded_args = urllib.urlencode(query_args)
    headers = { 'User-Agent' : 'Mozilla/5.0' }
    req = urllib2.Request(url + encoded_args, headers=headers)

    json_results = urllib2.urlopen(req)
    results = json.load(json_results)

    return [change_keys(data, result) for result in results]
Ejemplo n.º 4
0
    model.eval()

    print('Model loaded')

    print('Loading data')

    if args.eval:
        test_utts = read_trials(args.trials_path, eval_=args.eval)
    else:
        test_utts, attack_type_list, label_list = read_trials(args.trials_path,
                                                              eval_=args.eval)

    data = {k: m for k, m in read_mat_scp(args.path_to_data)}

    if args.tandem:
        data = change_keys(data)

    print('Data loaded')

    print('Start of scores computation')

    score_list = []

    with torch.no_grad():

        for i, utt in enumerate(test_utts):

            feats = prep_feats(data[utt])

            try:
                if args.cuda:
Ejemplo n.º 5
0
def download_engineering_table(url: str,
                               db: CourseDB,
                               col_name: str,
                               save_year_course: bool = True,
                               drop_frist: bool = True) -> str:
    page = get_page(url)

    soup = BeautifulSoup(page, 'html.parser')
    course_groups_html = soup.find_all('table')[1:]

    course_table = []
    if drop_frist:
        db.drop_col(col_name)

    for course_group_html in course_groups_html:
        course_headers = [
            tag.string for tag in course_group_html.tr.find_all('th')
        ]
        # print(course_headers)
        all_courses = course_group_html.find_all('tr')[1:]
        for index, meeting_html in enumerate(all_courses):
            meeting_info = [
                info.string if info.string != '\xa0' else 'NONE'
                for info in meeting_html.find_all('font')
            ]

            course_type = meeting_info[0][-1]
            course_name = meeting_info[0]

            if not save_year_course and course_type.capitalize() == 'Y':
                continue

            course_found = False
            detail_raw = {
                header: context
                for header, context in zip(course_headers[2:],
                                           meeting_info[2:])
            }
            detail_info = change_keys(
                detail_raw, {
                    "START DATE": 'meetingStartDate',
                    "DAY": 'meetingDay',
                    "START": 'meetingStartTime',
                    "FINISH": 'meetingEndTime',
                    "LOCATION": 'meetingLocation',
                    "PROFESSOR(S)": 'instructor',
                    "SCHEDULING NOTES": 'notes'
                })
            detail_info.update(
                {'meetingDay': parse_day(detail_info['meetingDay'])})
            instructor = detail_info['instructor']
            meeting = {
                'meetingName': meeting_info[1],
                'meetingType': meeting_info[1][:3],
                'instructors': [] if instructor == 'NONE' else [instructor],
                'detail': [detail_info]
            }
            meeting_type = meeting.pop('meetingType')

            # check for previous course name
            for previous_course in course_table:
                if previous_course['courseName'] == meeting_info[0]:

                    # check for previous meeting type first
                    meeting_type_found = False
                    for (previous_meeting_type,
                         meetings) in previous_course['meetings'].items():
                        if previous_meeting_type == meeting_type:

                            # check for previous meeting name
                            meeting_found = False
                            for previous_meeting in meetings:
                                if previous_meeting['meetingName'] == meeting[
                                        'meetingName']:

                                    # update instructor list
                                    instructor_found = False
                                    for previous_instructor in previous_meeting[
                                            'instructors']:
                                        if previous_instructor == meeting[
                                                'instructors'][0]:
                                            instructor_found = True
                                            break
                                    if not instructor_found:
                                        previous_meeting['instructors'].extend(
                                            meeting['instructors'])

                                    previous_meeting['detail'].extend(
                                        meeting['detail'])
                                    meeting_found = True
                                    break

                            if not meeting_found:
                                # no previous meeting found
                                meetings.append(meeting)

                            meeting_type_found = True
                            break

                    if not meeting_type_found:
                        # add a new type
                        previous_course['meetings'].update(
                            {meeting_type: [meeting]})

                    course_found = True
                    break

            if not course_found:
                # add a new course
                course_table.append({
                    'courseName': course_name,
                    'courseType': course_type,
                    'meetings': {
                        meeting_type: [meeting]
                    }
                })

            print('[ENG] Reading Session Detail - ' + course_name + ' - ' +
                  bcolors.OKBLUE +
                  'Progress {} of {}'.format(index + 1, len(all_courses)) +
                  bcolors.ENDC)

    db.insert_many(col_name, course_table)