Skip to content

Instantly share code, notes, and snippets.

View niconoe's full-sized avatar
🏠
Working from home

Nicolas Noé niconoe

🏠
Working from home
  • Niconoe.eu
  • Lillois, Belgium
View GitHub Profile
@niconoe
niconoe / django_test_client_cors.py
Last active March 4, 2022 10:31
Test CORS is enabled via the Django test client
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",
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):
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': [
-- 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)
);
@niconoe
niconoe / gist:3593689d164985a5e3b5f0300c2ab649
Last active November 6, 2020 13:07
Python: Synchronously (block until it's ready) request a GBIF download
# 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
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'
$ brew install aha
$ script -q /dev/null python manage.py mycommand | aha > command.html