def monuser(): from faker import Faker fake = Faker() user = User.create(username='******', password='******', first_name=fake.first_name(), last_name=fake.last_name(), email=fake.email()) Publication.create(title=fake.sentence(), body=fake.text(), user_created=user)
def fakedata(): from faker import Faker fake = Faker() for user_ex in range(0, 5): user = User.create(username=fake.last_name(), password=fake.password(), first_name=fake.first_name(), last_name=fake.last_name(), email=fake.email()) for publications_ex in range(0, 10): Publication.create(title=fake.sentence(), body=fake.text(), user_created=user)
def get_citation_count(query, fetch_index, api_key): # Request for citation counts for the publication params = DEFAULT_PARAMS.copy() params['expr'] = ( "AND(" + # we will search based on two criteria: "Ti=\'{title}\'...," + # the title prefix "Y={year})" # the publication year ).format(title=query['title'], year=int(query['year'])) response = make_request( default_requests_session.get, URL, params=params, headers={'Ocp-Apim-Subscription-Key': api_key}, ) time.sleep(REQUEST_DELAY) # enforce a pause between each fetch to be respectful to API # Go no further if the call failed if not response: return publications = response.json()['entities'] if len(publications) == 0: logger.warn("No publications found for title: %s", query['title']) return # Store data from the fetched publications first_publication = publications[0] authors = ','.join([author['AuN'] for author in first_publication['AA']]) Publication.create( fetch_index=fetch_index, citation_count=first_publication['CC'], author=authors, year=first_publication['Y'], title=first_publication['Ti'], )
def publi_create(): publi = Publication.create(title='osef', body='essai', username=user) assert publi.user_created == datetime.datetime.now