Skip to content

Instantly share code, notes, and snippets.

View JonathanGarro's full-sized avatar

Jonathan Garro JonathanGarro

  • American Red Cross
  • Washington DC
View GitHub Profile
@JonathanGarro
JonathanGarro / inform_ranker.py
Last active July 24, 2024 18:44
Reads a simplified version of the INFORM Index output and finds top 20 countries with highest natural hazard risk and vulnerability, along with lowest coping capacity, all normalized against population
# script reviews a simplified version of INFORM index data
# and harmonizes natural hazards, vulnerability, and coping capacity
# then normalizes with population from 2023
import pandas as pd
file_path = 'INFORM.xlsx'
xls = pd.ExcelFile(file_path)
ranks_df = pd.read_excel(xls, 'ranks')
@JonathanGarro
JonathanGarro / go_learnings_downloader.py
Last active July 17, 2024 15:19
Downloads all learning data from the GO API
# Given the paginated results, this script can take a few minutes to run. Be patient!
import requests
import csv
base_url = "https://goadmin.ifrc.org/api/v2/ops-learning/"
def fetch_data(url):
"""
Fetches data from the URL passed into it.
@JonathanGarro
JonathanGarro / flag_downloader.py
Last active June 23, 2024 15:43
A tool to download all of the flag thumbnails from a CDN
#!/usr/bin/env python3
import requests
iso2_codes = [
"AF", "AX", "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", "AZ",
"BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BQ", "BA", "BW", "BV", "BR",
"IO", "BN", "BG", "BF", "BI", "CV", "KH", "CM", "CA", "KY", "CF", "TD", "CL", "CN", "CX", "CC",
"CO", "KM", "CD", "CG", "CK", "CR", "HR", "CU", "CW", "CY", "CZ", "DK", "DJ", "DM", "DO", "EC",
"EG", "SV", "GQ", "ER", "EE", "SZ", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", "GA",
@JonathanGarro
JonathanGarro / get_ns_data.py
Last active January 17, 2024 19:31
Save IFRC GO Country List to CSV
import math
import csv
# script requires requests library
# prompt user in console to auto pip install it
try:
import requests
except ImportError as e:
response = input("The required module 'requests' is not installed. Would you like to install it now? (yes/no): ")
if response.lower() in ['yes', 'y']:
@JonathanGarro
JonathanGarro / Download All GO Appeals to CSV.py
Last active July 25, 2024 13:59
Get a set number of pages of GO Appeal data
#!/usr/bin/env python3
import csv
import requests
def flatten_dict(d, parent_key='', sep='_'):
"""
recursively flattens a nested dictionary to handle GO API data structure.
function takes a dictionary that may contain nested dictionaries
@JonathanGarro
JonathanGarro / spinning_globe.js
Created July 20, 2023 12:16
Spinning Globe with Point Markers in D3.js
const width = 750;
const height = 750;
const config = {
speed: 0.01,
verticalTilt: -12,
horizontalTilt: 0
};
let locations = [];
const svg = d3.select('svg').attr('width', width).attr('height', height);
const markerGroup = svg.append('g');
@JonathanGarro
JonathanGarro / opencage_geocoder.py
Last active July 14, 2023 12:15
Get admin info from list of coordinates
import csv
import pandas as pd
from geopy.geocoders import OpenCage
# insert your OpenCage API key
geocoder = OpenCage('<YOUR_API_KEY_HERE>')
# load locations with pandas
location_data = 'largest_cities_coordinates.csv'
data = pd.read_csv(location_data)
@JonathanGarro
JonathanGarro / globe.html
Created June 30, 2023 19:37
Spinning Globe with Points in D3.js
<svg viewBox="100 0 650 650" preserveAspectRatio="none"></svg>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/topojson.v1.min.js"></script>
<script>
const width = 750;
const height = 750;
const config = {
speed: 0.01,
verticalTilt: -12,
horizontalTilt: 0
"""
Update the event ID and insert your token (leaving quotes around the token code).
Save this script in a specific folder where you want the CSV that it generates to also be saved.
Note that you will need to update the tags_list values when new profile types are added to RRMS.
"""
import requests
import pandas
import csv
@JonathanGarro
JonathanGarro / bulk_geocoder.py
Last active April 10, 2023 12:09
A Python script to find coordinates from addresses via Google API
#!/usr/bin/env python3
import googlemaps
import pandas as pd
import csv
# save this script in the same folder as your CSV file, then update the name of the file below
location_data = 'file_name_here.csv'
data = pd.read_csv(location_data)