Skip to content

Instantly share code, notes, and snippets.

View fmasanori's full-sized avatar

Fernando Masanori fmasanori

View GitHub Profile
@fmasanori
fmasanori / find.py
Created May 21, 2013 14:41
Find Images Files on Hard Disck C
import fnmatch
import os
imagens = ['*.jpg', '*.jpeg', '*.png', '*.tif', '*.tiff']
achados = []
for raiz, diretórios, arquivos in os.walk("C:\\"):
for extensões in imagens:
for arq in fnmatch.filter(arquivos, extensões):
print (raiz + '\\' + arq)
@fmasanori
fmasanori / json_missing.py
Last active December 17, 2015 13:49
json object_hook
import urllib.request
import json
from pprint import pprint
class Dic42(dict):
def __missing__(self, key):
return '42'
url = 'https://graph.facebook.com/fmasanori'
resp = urllib.request.urlopen(url).read()
@fmasanori
fmasanori / ChuckJokes.py
Created July 1, 2013 14:47
ChuckJokes Python2
import urllib
import json
url = 'http://api.icndb.com/jokes/random?limitTo=[nerdy]'
resp = urllib.urlopen(url).read()
data = json.loads(resp)
print (data['value']['joke'])
@fmasanori
fmasanori / FB Profile.py
Last active December 19, 2015 04:59
Facebook Profile Python2
#deprecated with in 30 April, 2015, with new 2.0 Facebook API
import urllib
import json
from pprint import pprint
url = 'https://graph.facebook.com/fmasanori'
resp = urllib.urlopen(url).read()
data = json.loads(resp)
pprint(data)
@fmasanori
fmasanori / FB Profile Photo.py
Created July 1, 2013 14:54
Facebook Profile Photo
import urllib
url = 'https://graph.facebook.com/1183621847/picture?type=large'
imagem = urllib.urlopen(url).read()
f = open('foto.jpg', 'wb')
f.write(imagem)
f.close()
print ('Foto do perfil gravada...')
@fmasanori
fmasanori / CRUD MongoDB.py
Last active September 1, 2020 14:29
CRUD MongoDB Python2
from datetime import datetime
from pymongo import MongoClient
connection = MongoClient("mongodb://localhost")
db = connection.test
post = {"title": "My Blog Post",
"content": "Here's my blog post.",
"date": datetime.utcnow()}
@fmasanori
fmasanori / CRUD Web MongoDB.py
Last active December 19, 2015 05:19
CRUD Web MongoDB
import bottle
import pymongo
@bottle.route('/')
def index():
from pymongo import MongoClient
connection = MongoClient("mongodb://localhost")
db = connection.test
names = db.names
@fmasanori
fmasanori / CRUD Excepion.py
Last active February 12, 2019 13:42
CRUD MongoDB exception
import pymongo
import sys
def main():
connection = pymongo.MongoClient("mongodb://localhost")
db = connection.m101
people = db.people
person = {'name': 'Barack Obama', 'role':'President',
'address':{'address1':'The White House',
'street': '1600 Pensylvania Avenue',
@fmasanori
fmasanori / tutorial bottle 01.py
Last active February 26, 2018 12:30
Tutorial bottle 01
import bottle
#this is the handler for the root address on the web browser
@bottle.route('/')
def home_page():
return 'Hello Bottle World\n'
@bottle.route('/testpage')
def test_page():
return 'Oficina MongoDB e Python no FISL'
@fmasanori
fmasanori / tutorial bottle 02.py
Created July 3, 2013 21:23
tutorial bottle 02
import bottle
@bottle.route('/')
def home_page():
mythings = ['apple', 'orange', 'banana', 'peach']
return bottle.template('hello_world', {'username':'Masanori',
'things':mythings})
bottle.debug(True)