Skip to content

Instantly share code, notes, and snippets.

import logging
# Create a custom logger
logger = logging.getLogger(__name__)
# Create a handler
f_handler = logging.FileHandler('file.log')
# Create a formatter and add it to the handler
f_format = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
@marcogoldin
marcogoldin / bootstrap_style_dash_data_table.py
Last active November 28, 2022 15:30
Dash DataTable Bootstrap style
import dash_html_components as html
import dash_table
import pandas as pd
def data_table(df):
table = html.Div(
className='table table-responsive-md p-3',
children=dash_table.DataTable(
id='tabella-milano',
@marcogoldin
marcogoldin / fetchall_athena.py
Created February 15, 2020 14:11 — forked from schledererj/fetchall_athena.py
Using boto3 and paginators to query an AWS Athena table and return the results as a list of tuples as specified by .fetchall in PEP 249
# Does NOT implement the PEP 249 spec, but the return type is suggested by the .fetchall function as specified here: https://www.python.org/dev/peps/pep-0249/#fetchall
import time
import boto3
# query_string: a SQL-like query that Athena will execute
# client: an Athena client created with boto3
def fetchall_athena(query_string, client):
query_id = client.start_query_execution(
QueryString=query_string,
biblioCode Biblioteca Titoli unici prestati Titoli in catalogo Percentuale titoli prestati sul catalogo
RM0635 BIBLIOTECA GUGLIELMO MARCONI 16425 61117 26.9 %
RM0627 BIBLIOTECA NELSON MANDELA 11968 33639 35.6 %
RM0632 BIBLIOTECA ELSA MORANTE 11561 30479 37.9 %
RM0621 BIBLIOTECA ENNIO FLAIANO 10937 21268 51.4 %
RM1417 BIBLIOTECA CORNELIA 10287 29942 34.4 %
RM1453 BIBLIOTECA SANDRO ONOFRI 9609 32044 30.0 %
RM0633 BIBLIOTECA FRANCO BASAGLIA 9595 30874 31.1 %
RM1485 BIBLIOTECA EUROPEA 9275 27930 33.2 %
RM1149 BIBLIOTECA GIANNI RODARI 9207 27141 33.9 %
@marcogoldin
marcogoldin / doing_it_anyway.py
Last active April 22, 2019 05:14
Simple crawler
import pandas as pd
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
opts = Options()
opts.headless = True
driver = webdriver.Firefox(executable_path='../geckodriver', options=opts)
def crawler(codice_isbn):
driver.get('https://opac.sbn.it/opacsbn/opac/iccu/avanzata.jsp')
print(f'Titolo della pagina: {driver.title}')
pd.read_csv('https://www.metoffice.gov.uk/pub/data/weather/uk/climate/datasets/Tmin/ranked/UK.txt?fbclid=IwAR26RJZPfZYJd4GJ5bn4zmAHlXkGmDj4UPxujCIgLWFW5ErgM9AWkmpG_IM',\
skiprows=6, \
sep=' ')