This file contains 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
$ brew install aha | |
$ script -q /dev/null python manage.py mycommand | aha > command.html |
This file contains 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 dwca.read import DwCAReader | |
import os | |
import psutil | |
pid = os.getpid() | |
py = psutil.Process(pid) | |
# Should have the same content than your data file (that I had trouble downloading for some reason) | |
DWCA_PATH = '0047730-200613084148143.zip' |
This file contains 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
# Quick and dirty gist to show how to request a GBIF download, block until it's ready then finally download it. | |
# (no need to monitor an email address, nor to install PyGBIF and all its dependencies. Only requests is needed) | |
# TODO: use download id as filename | |
# TODO: improve make_predicate function so it's much more flexible | |
from time import sleep | |
import requests | |
SLEEP_DURATION = 20 |
This file contains 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
-- Table definitions | |
DROP TABLE IF EXISTS sensors; | |
DROP TABLE IF EXISTS projects; | |
DROP VIEW IF EXISTS projects_matrix_sensors; | |
CREATE TABLE projects ( | |
id INTEGER PRIMARY KEY, | |
name CHAR(50) | |
); |
This file contains 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 pandas as pd | |
import json | |
source_df = pd.read_csv('./data_agouti.csv') | |
def pd_row_to_dict(row): | |
return { | |
'taxon_id': row['taxon_id'], | |
'scientific_name': row['scientific_name'], | |
'vernacular_names': [ |
This file contains 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 | |
def get_json_from_url(url): | |
"""Small helper""" | |
res = requests.get(url) | |
data = res.json() | |
return data | |
def get_resource_for_dp(resource_for_export): |
This file contains 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 django.test import TestCase | |
class ApiTests(TestCase): | |
def test_cors_enabled(self): | |
"""Make sure CORS is enabled a given endpoint | |
# Technique inspired from https://stackoverflow.com/a/47609921 | |
""" | |
request_headers = { | |
"HTTP_ACCESS_CONTROL_REQUEST_METHOD": "GET", |