-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
376 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
github doesn't like empty folders |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import time | ||
import requests | ||
import unicodedata | ||
import re | ||
from bs4 import BeautifulSoup | ||
titles=[] | ||
authors=[] | ||
dates=[] | ||
abstracts=[] | ||
links=[] | ||
tags=[] | ||
author_aff=[] | ||
|
||
##get all articles | ||
|
||
categories=['biology','medicine_pharmacology','life_sciences'] | ||
|
||
base='http://preprints.org/subject/browse/' | ||
|
||
for cat in categories: | ||
index=1 | ||
print cat | ||
templinks=[] | ||
tempdates=[] | ||
tempabstracts=[] | ||
tempauthors=[] | ||
temptags=[] | ||
while True: | ||
print index | ||
r=requests.get(base+cat+'?page_num='+str(index)+'&page_length=100') | ||
print r.ok | ||
count=0 | ||
soup=BeautifulSoup(r.content,'html.parser') | ||
for i in soup.find_all("a", {'class':'title'}): | ||
templinks.append(i.get('href')) | ||
templinks=templinks[:-1] | ||
for i in soup.find_all('div',{'class','search-content-box'}): | ||
tempdate=i.find('div',{'class','show-for-large-up'}).text.strip().split('Online: ')[1].split(' (')[0].strip().split() | ||
tempdates.append(tempdate[1]+' '+tempdate[0]+' '+tempdate[2]) | ||
count+=1 | ||
for i in soup.find_all('div',{'class','abstract-content'}): | ||
tempabstracts.append(i.text) | ||
for i in soup.find_all('div',{'class','search-content-box-author'}): | ||
tempauthors.append([unicodedata.normalize('NFKD',j.text).encode('ascii','ignore') for j in i.find_all('a')]) | ||
for i in soup.find_all('div',{'class','search-content-box'}): | ||
temptags.append([i.find_all('div')[4].text.strip().split(', ')[1].split(';')[0].strip()]) | ||
if count==100: | ||
index+=1 | ||
else: | ||
break | ||
|
||
for i,j,k,l,m in zip(templinks,tempdates,tempabstracts,tempauthors,temptags): | ||
if 'manuscript' in i: | ||
print i | ||
r=requests.get('http://preprints.org'+i) | ||
soup=BeautifulSoup(r.content,'html.parser') | ||
if soup.find('span',{'class','type-span'}).text in ['Review','Article']: | ||
dates.append(j) | ||
titles.append(soup.find('h1').text.strip()) | ||
abstracts.append(k) | ||
links.append(i) | ||
authors.append(l) | ||
temp_aff=[] | ||
for aff in soup.find('div',{'class','manuscript-affiliations'}).find_all('li'): | ||
temp_aff.append(aff.text) | ||
author_aff.append(temp_aff) | ||
tags.append(m) | ||
|
||
|
||
else: | ||
pass | ||
|
||
|
||
|
||
if len(titles)==len(authors)==len(dates)==len(abstracts)==len(links)==len(tags)==len(author_aff): | ||
f=open('preprints.txt','w') | ||
for title,author,date,abstract,link,tag,author_af in zip(titles,authors,dates,abstracts,links,tags,author_aff): | ||
f.write(str([title,author,date,abstract,link,tag,author_af])) | ||
f.write('\n') | ||
f.close() | ||
else: | ||
print 'error' | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
github doesn't like empty folders |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import os | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings') | ||
|
||
import django | ||
django.setup() | ||
|
||
from papers.models import Article | ||
from papers.models import Tag | ||
from papers.models import Affiliation | ||
from papers.models import Author | ||
from datetime import date as dt | ||
|
||
|
||
|
||
f=open(r'C:\Users\Jordan Anaya\Desktop\prepub\preprints\preprints.txt') | ||
preprints=[eval(i.strip()) for i in f] | ||
|
||
##work on dates | ||
date_dict={"January":1,"February":2,"March":3,"April":4,"May":5,"June":6,\ | ||
"July":7,"August":8,"September":9,"October":10,"November":11,"December":12, | ||
"Jan":1,"Feb":2,"Mar":3,"Apr":4,"May":5,"Jun":6,\ | ||
"Jul":7,"Aug":8,"Sep":9,"Oct":10,"Nov":11,"Dec":12} | ||
|
||
|
||
|
||
for i in preprints: | ||
paper=Article(title=i[0],abstract=i[3],link='https://www.preprints.org'+i[4]) | ||
temp=i[2].split() | ||
paper.pub_date=dt(int(temp[2]),date_dict[temp[0]],int(temp[1])) | ||
paper.save() | ||
temp=[] | ||
for author in i[1]: | ||
name=author.replace(',','').replace('.','') | ||
if name[:3].lower()=='jr ': | ||
name=name[3:] | ||
if name[-3:].lower()==' jr': | ||
name=name[:-3] | ||
if name[:3].lower()=='sr ': | ||
name=name[3:] | ||
if name[-3:].lower()==' sr': | ||
name=name[:-3] | ||
first_name=name.split()[0] | ||
last_name=name.split()[-1] | ||
if len(name.split())==2: | ||
middle_name='' | ||
else: | ||
middle_name=name.replace(first_name+' ','').replace(' '+last_name,'').strip() | ||
if middle_name!='': | ||
temp.append(first_name+' '+middle_name+' '+last_name) | ||
else: | ||
temp.append(first_name+' '+last_name) | ||
try: | ||
auth=Author.objects.get(first=first_name,middle=middle_name,last=last_name) | ||
paper.authors.add(auth) | ||
except: | ||
auth=Author.objects.create(first=first_name,middle=middle_name,last=last_name) | ||
paper.authors.add(auth) | ||
paper.author_list=str(temp) | ||
for affiliation in i[-1]: | ||
try: | ||
aff=Affiliation.objects.get(name=affiliation) | ||
paper.affiliations.add(aff) | ||
except: | ||
aff=Affiliation.objects.create(name=affiliation) | ||
paper.affiliations.add(aff) | ||
for t in i[-2]: | ||
try: | ||
tag=Tag.objects.get(name=t) | ||
paper.tags.add(tag) | ||
except: | ||
tag=Tag.objects.create(name=t) | ||
paper.tags.add(tag) | ||
paper.save() | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.