-
-
Save usametov/d47af17ceaaf3433ce264eadbb4d5d1b to your computer and use it in GitHub Desktop.
Example for calling SNPedia API from python
This file contains hidden or 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import mwclient | |
from mwclient import Site | |
def save_snips(agent, site, path): | |
""" | |
http://snpedia.com/index.php/Bulk | |
https://mwclient.readthedocs.io/en/latest/user/page-ops.html | |
gets all snips from snpedia | |
""" | |
f = open(path, "w") | |
for i, page in enumerate(site.Categories['Is_a_snp']): | |
f.write(page.name) | |
f.write('\n') | |
def get_snpedia_content(agent, site, snips, output_dir): | |
""" | |
grabs pages | |
""" | |
for sn in snips: | |
with open(f'{output_dir}/{sn}.txt', "w") as f: | |
page = site.pages[sn] | |
f.write(page.text()) | |
def load_snips(path): | |
with open(path, "r") as f: | |
return f.read().splitlines() | |
def _main(): | |
agent = 'MySNPBot. Run by User:[email protected] Using mwclient/' + mwclient.__version__ | |
site = mwclient.Site('bots.snpedia.com', path='/',clients_useragent=agent) | |
# uncomment this line if you want to grap snips first | |
# save_snips(agent, site, "./snips.txt") | |
snips = load_snips("bioc-data/snips-nebula.txt") | |
# these are snips from my nebula reports | |
get_snpedia_content(agent, site, snips, "bioc-data") | |
if __name__ == '__main__': | |
_main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment