Skip to content

Commit

Permalink
Refactor download_pathway_archive.py to use new JSON-API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
kozo2 committed Sep 23, 2024
1 parent 4d949db commit aa07dc2
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions pywikipathways/download_pathway_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,16 @@ def download_pathway_archive(date='current', organism=None, format='gpml', destp
# download specific file, or...
if organism:
if date == 'current':
curr_files = pandas.read_html("https://wikipathways-data.wmcloud.org/current/" + format)[0]['Filename']
filename = curr_files[curr_files.str.contains(organism.replace(" ", "_"))]
filename = list(filename)[0]
if not True in curr_files.str.contains(organism.replace(" ", "_")):
curr_files = pandas.read_html("https://data.wikipathways.org/current/" + format)[0]["File Name"]
filename = curr_files[curr_files.str.contains(organism.replace(" ", "_"))].iloc[0]
if len(filename) == 0:
sys.exit('Could not find a file matching your specifications. Try browsing http://data.wikipathways.org.')
else:
if requests.get("https://wikipathways-data.wmcloud.org/" + date).ok:
ext = ".zip"
if format == 'gmt':
ext = ".gmt"
filename = "-".join(['wikipathways', date, format, organism.replace(" ", "_")]) + ext
url = "/".join(['http://data.wikipathways.org', date, format, filename])
ext = ".zip"
if format == 'gmt':
ext = ".gmt"
filename = "-".join(['wikipathways', date, format, organism.replace(" ", "_")]) + ext
url = "/".join(['https://data.wikipathways.org', date, format, filename])
r = requests.get(url)
file = open(filename, "wb")
file.write(r.content)
Expand Down

0 comments on commit aa07dc2

Please sign in to comment.