aboutsummaryrefslogtreecommitdiff
path: root/ncbi/dbsnp/ncbiutils.py
blob: 8fb998b20ad6f15f286f4636c20cfed46c1529de (plain) (blame)
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
#!/usr/bin/env python3

import requests

BASE_URL = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?"

# Example https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=snp&term=snp_pubmed_cited[sb]&retmax=200000&retstart=1000&retmode=json
def db_query(**kwargs):
    args = []
    for key, value in kwargs.items():
        args.append(key+"="+str(value))
    qstring = "&".join(args)
    print(qstring)
    resp = requests.get(BASE_URL + qstring)
    if resp.status_code == 200:
        results = resp.json()
        return(results)
    else:
        print("You've encountered an error and we can't return your results")

def main():
    results = db_query(db="snp", term="snp_pubmed_cited[sb]", retmax=200000, retstart=1000, retmode="json")
    print(results)
    return()

if __name__ == '__main__':
    main()