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
import requests | |
import json | |
import time | |
'''Decorator for retrying up to 10 times''' | |
def retry(exception): | |
def outer_retry(f): | |
def inner_retry(*args,attempt=0): | |
n=0 | |
while True: |
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
focus_areas = ['Education Innovation and Technology', | |
'Health Information Technology and Bioinformatics', | |
'Public Health, Non-Communicable Diseases and Wellness', | |
'Biotechnology and Genomics', | |
'Water Management and Economics', | |
'Solar and Alternative Energy Technology Systems', | |
'Space Sciences', | |
'Cubesats and Nanosatellites', | |
'Cybersecurity', | |
'Semiconductor Process Development', |
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
# Geometry, shapefiles and projections | |
import fiona | |
from shapely.geometry import shape | |
from shapely.geometry import Point | |
import pyproj | |
# Generate a function to create a UK East/North point from Lon/Lat | |
wgs84 = pyproj.Proj(init = 'epsg:4326') | |
ukgrid = pyproj.Proj(init = 'epsg:27700') | |
EnPoint = lambda lon, lat : Point(*pyproj.transform(wgs84, ukgrid, lon, lat)) |
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
# Python tools | |
from matplotlib import pyplot as plt | |
import pandas as pd | |
import math | |
import numpy as np | |
from collections import defaultdict | |
from functools import partial | |
from mpl_toolkits.axes_grid1.inset_locator import inset_axes | |
import matplotlib as mpl |
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
# Uncomment this for notebooks | |
# %matplotlib inline | |
import matplotlib as mpl | |
from matplotlib.patches import Polygon | |
from matplotlib.collections import PatchCollection | |
from mpl_toolkits.basemap import Basemap | |
import numpy as np | |
# Country codes --> alpha |
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
import gender_guesser.detector as gender | |
import pandas as pd | |
path_to_file = "~/Downloads/test_names.xlsx" | |
d = gender.Detector() | |
data = pd.read_excel(path_to_file) | |
for name in data["names"].values: | |
print(d.get_gender(name)) |
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
from selenium import webdriver | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions | |
import os | |
import time | |
def wait_and_find(driver, element_id, load_time): | |
time.sleep(load_time/3) |
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
# Note superfuzz can be found here: https://github.com/jaklinger/nesta_toolbox/blob/master/sandbox/jaklinger/superfuzz/superfuzz.py | |
import requests | |
from retrying import retry | |
import re | |
import time | |
from collections import Counter | |
from superfuzz.superfuzz import superfuzz | |
from fuzzywuzzy import fuzz | |
from fuzzywuzzy import process as fuzzy_process |
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
-- Selecting nested elements (e.g. author names) | |
select author -> 'name' as author_name | |
from microsoft_academic_graph | |
cross join jsonb_array_elements(microsoft_academic_graph.paper -> 'authors') author | |
limit 1; | |
-- Finding specific papers by author | |
select paper->'title', paper->'authors' | |
from microsoft_academic_graph | |
where paper->'authors' @> '[{"name":"John Smith"}]' |
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
from sqlalchemy import create_engine | |
from sqlalchemy import text as sql_text | |
# Stolen from https://stackoverflow.com/a/434328/1571593 | |
def chunker(seq, size): | |
return (seq[pos:pos + size] for pos in range(0, len(seq), size)) | |
# Execute {SELECT ... IN ...} in chunks | |
'''Notes: | |
1) query has to be of the form: |
OlderNewer