-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15_check_open_access.py
More file actions
executable file
·52 lines (42 loc) · 1.41 KB
/
15_check_open_access.py
File metadata and controls
executable file
·52 lines (42 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/python3 -u
import os
from bs4 import BeautifulSoup
from utils.mysql import *
import urllib3
#########################
http = urllib3.PoolManager()
def convert_pm(pm):
url = "https://www.ncbi.nlm.nih.gov/pmc/utils/idconv/v1.0/?ids=%d" % pm
r = http.request('GET', url)
soup = BeautifulSoup(r.data.decode("utf-8"), "lxml")
rec = soup.find('record')
pmcids = []
for child in rec.children:
if child.name != 'versions': continue
for grand in child.children:
if not grand.has_attr("current"): continue
if grand["current"] == "true" and grand.has_attr("pmcid"):
pmcids.append(grand["pmcid"].strip())
return ",".join(pmcids)
#########################################
def main():
db = connect_to_mysql("/home/ivana/.tcga_conf")
cursor = db.cursor()
search_db(cursor, "set autocommit=1")
db.set_character_set('utf8mb4')
cursor.execute('SET NAMES utf8mb4')
cursor.execute('SET CHARACTER SET utf8mb4')
cursor.execute('SET character_set_connection=utf8mb4')
switch_to_db(cursor,"gnao1")
pubs = hard_landing_search(cursor, "select id, pubmed from publications")
for dbid, pubmed in pubs:
pmc_ids = convert_pm(pubmed)
if len(pmc_ids)==0: continue
print(dbid, pubmed, pmc_ids)
qry = "update publications set pubmedcentral='%s' where id=%d" %(pmc_ids, dbid)
error_intolerant_search(cursor, qry)
cursor.close()
db.close()
#########################################
if __name__ == '__main__':
main()