File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 22import pandas as pd
33import json
44from 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+
743def today ():
844 """
945 Get today's snapshot of Brain Image Library.
You can’t perform that action at this time.
0 commit comments