Skip to content

Commit 4a9c76d

Browse files
authored
46 - get_data update
1 parent eefec85 commit 4a9c76d

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

braininventory/get.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,44 @@
22
import pandas as pd
33
import json
44
from datetime import date
5+
import calendar
6+
import pandas as pd
7+
import urllib.request
8+
import random
9+
import requests
10+
import calendar
11+
12+
13+
url = 'https://download.brainimagelibrary.org/inventory/daily/reports/today.json'
14+
file_path, _ = urllib.request.urlretrieve(url)
15+
df = pd.read_json(file_path)
516

17+
def get_jsonFile(df):
18+
"""
19+
Input: dataframe
20+
Output:open the jsonFile that was located in datasets Brain Image Library dataframe
21+
"""
22+
isNotZero = df[df["score"] != 0.0] #only have files with the correct data
23+
randomRow = isNotZero.iloc[random.randint(0, len(isNotZero))] #select a random row of random index
24+
jsonFileLink = randomRow.json_file.replace("/bil/data", "https://download.brainimagelibrary.org", 1) #create the link
25+
result = requests.get(jsonFileLink)
626

27+
return result.json()
28+
29+
def get_date(df):
30+
"""
31+
Input: dateframe
32+
Output: date data was created in year-day-month format
33+
"""
34+
jsonFile = get_jsonFile(df) #get the jsonFile information with get_jsonFile() function
35+
dateList = jsonFile['creation_date'].split() #get creation_date
36+
mntList = dict((month, index) for index, month in enumerate(calendar.month_abbr) if month) #month abbr to number
37+
yr = dateList[4] #get year
38+
mnt= mntList[dateList[1]] #get month
39+
day = dateList[2] #get day
40+
print(f"{yr}-{day}-{mnt}") #format in year-day-month
41+
42+
743
def today():
844
"""
945
Get today's snapshot of Brain Image Library.

0 commit comments

Comments
 (0)