Skip to content

Instantly share code, notes, and snippets.

View sergiolucero's full-sized avatar
💭
coding the days away

Sergio Lucero sergiolucero

💭
coding the days away
View GitHub Profile
@sergiolucero
sergiolucero / xlsb_to_csv.py
Created January 25, 2018 05:18
splitting an xlsb file into several CSVs
import csv
from pyxlsb import open_workbook
with open_workbook('PUB_Reg_Com_Rub_Sub_Act.xlsb') as wb:
for sheetname in wb.sheets:
print(sheetname)
ofile = open(sheetname.split('_')[0]+'.csv', "w")
writer = csv.writer(ofile, delimiter=',',
quotechar='"', quoting=csv.QUOTE_ALL)
with wb.get_sheet(sheetname) as sheet:
@sergiolucero
sergiolucero / datachile_first.py
Last active September 30, 2020 20:44
first use of datachile API
import pandas as pd
import matplotlib.pyplot as plt
import squarify # pip install squarify (algorithm for treemap)
from datachile import ChileCube
client = ChileCube()
query = client.get("exports",
{"drilldowns": [
["Date", "Year"],
["Destination Country", "Country", "Country"]
@sergiolucero
sergiolucero / mercantil_scraper.py
Last active March 23, 2018 19:26
scraping mercantil
import time
from bs4 import BeautifulSoup
from selenium import webdriver
base_url='https://www.mercantil.com/restaurantes/1502/'
driver = webdriver.Firefox()
driver.get(base_url)
for item in range(10):
@sergiolucero
sergiolucero / boston_teapot
Created April 5, 2018 21:52
Boston Teapot Party!
from tpot import TPOTRegressor
from sklearn.datasets import load_boston
from sklearn.model_selection import train_test_split
housing = load_boston()
X_train, X_test, y_train, y_test = train_test_split(housing.data, housing.target,
train_size=0.75, test_size=0.25)
tpot = TPOTRegressor(generations=5, population_size=50, verbosity=2)
tpot.fit(X_train, y_train)
@sergiolucero
sergiolucero / foursquare_tsp.py
Last active April 8, 2018 13:31
som tsp from web
import json, requests
import pandas as pd
url = 'https://api.foursquare.com/v2/venues/explore'
CLIENT_ID = 'ES4CLZNVL5AX3E43RY1115LHJGZ2HIULJWLFMZFVH03MPHHO'
CLIENT_SECRET = 'OZZKEKTKH2BAIW3BNG3ZSM5MUOH444XJHQKQIZDDPFMDMBXN'
params = dict(
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
@sergiolucero
sergiolucero / citybikes_scraper.py
Last active April 21, 2018 04:39
scraping CityBikes (using python3!! pybikes is Python 2!!)
import pandas as pd
import sqlite3
import requests
import time
base_url = 'http://api.citybik.es'
list_tail = '/v2/networks/?fields=id,name,href'
nets = requests.get(base_url+list_tail).json()['networks'] # retrieves system list
print('FOUND: %d networks' %len(nets))
@sergiolucero
sergiolucero / blc_pybikes.py
Last active April 23, 2018 14:42
pybikes demo
import pybikes #pip install git+https://github.com/eskerda/pybikes.git
blc = pybikes.get('bicilascondes') # system added to Citybikes by yours truly!
blc.update()
print len(blc.stations) # usually, 89
print blc.stations[0]
'''
--- u'001 VITACURA / SAN PATRICIO' ---
bikes: 4
free: 15
latlng: -33.41138735,-70.60239197
@sergiolucero
sergiolucero / city_core.py
Last active April 23, 2018 14:38
core citybikes gist
import requests
base_url = 'http://api.citybik.es'
list_tail = '/v2/networks/?fields=id,name,href'
nets = requests.get(base_url+list_tail).json()['networks'] # retrieves system list
print('FOUND: %d networks' %len(nets)) # 561 last I checked on 20180423
print(nets[0])
# {'href': '/v2/networks/bbbike', 'id': 'bbbike', 'name': 'BBBike'}
@sergiolucero
sergiolucero / flaskgit.py
Created May 1, 2018 03:37
import microservices from git for flask
#git clone https://github.com/sanderjo/disk-speed.git
#idea! flask services should be gitable
urls = from git import my_dict
app = [(url,view) for url,view in my_dict]
Instrucciones para selenium+gecko+firefox
sudo apt-get update
sudo apt-get install python # instalar python
sudo apt-get install python-pip # instalar pip
pip install selenium # instalar selenium
pip install pyvirtualdisplay # instalar pyvirtualdisplay
wget https://github.com/mozilla/geckodriver/releases/download/v0.20.1/geckodriver-v0.20.1-linux64.tar.gz
tar -xvzf geckodriver* # extraer geckodriver