Skip to content

Instantly share code, notes, and snippets.

View fmasanori's full-sized avatar

Fernando Masanori fmasanori

View GitHub Profile
@fmasanori
fmasanori / ChuckJokesPython3.py
Last active September 5, 2023 11:36
Chuck Norris Nerd Jokes
from urllib.request import Request, urlopen
import json
req = Request(
url='https://api.chucknorris.io/jokes/random',
headers={'User-Agent': 'Mozilla/5.0'}
)
resp = urlopen(req).read()
data = json.loads(resp.decode('utf-8'))
@fmasanori
fmasanori / adivinha.py
Created July 18, 2013 13:05
Jogo simples em Python 3
from random import randint
print ('Bem vindo!')
sorteado = randint(1, 100)
chute = 0
while chute != sorteado:
chute = int(input ('Chute: '))
if chute == sorteado:
print ('Você venceu!')
else:
if chute > sorteado:
@fmasanori
fmasanori / Facebook Profile Python 3x.py
Created January 29, 2013 19:58
Python 3.x Facebook Profile
import urllib.request
import json
from pprint import pprint
url = 'https://graph.facebook.com/fmasanori'
resp = urllib.request.urlopen(url).read()
data = json.loads(resp.decode('utf-8'))
pprint (data)
@fmasanori
fmasanori / jogos.py
Last active October 30, 2022 00:00
World Cup in six lines of Python 3. Jogos da Copa do Mundo em cinco linhas de Python 3.
import requests
jogos = requests.get('http://worldcup.sfg.io/matches').json()
for jogo in jogos:
if jogo['status'] in ('completed', 'in progress'):
print (jogo['home_team']['country'], jogo['home_team']['goals'], 'x',
jogo['away_team']['country'], jogo['away_team']['goals'])
texto = open('alice.txt').read().lower()
from string import punctuation
for c in punctuation:
texto = texto.replace(c, ' ')
texto = texto.split()
dic = {}
for p in texto:
if p not in dic:
dic[p] = 1
else:
@fmasanori
fmasanori / Facebook Friends Photos Python 3x.py
Last active September 3, 2022 13:28
Python 3.x Facebook Friends Photos
#Sorry, in April 30, 2015, with Facebook 2.0 API update only friends that use the app will be show
import urllib.request
import json
def save_image(friend):
size = '/picture?width=200&height=200'
url = 'https://graph.facebook.com/'+ friend['id'] + size
image = urllib.request.urlopen(url).read()
f = open(friend['name'] + '.jpg', 'wb')
f.write(image)
@fmasanori
fmasanori / Oficina MongoDB e Python FISL
Last active August 22, 2022 11:07
Oficina MongoDB e Python FISL
Oficina MongoDB e Python - FISL
Resumo https://university.mongodb.com/courses/M220P/about
Install python 3.x (provavelmente vc já tem, 3.7 no mínimo)
https://www.python.org/downloads/
para testar python -V
Install mongoDB última versão (mínimo 4.x)
https://www.mongodb.org/downloads
criar diretório \data\db com as permissões necessárias para testar bin\mongod (servidor)
@fmasanori
fmasanori / dec2bin.py
Created August 4, 2014 14:19
Decimal para binário em Python 3
def dec2bin(n):
b = ''
while n != 0:
b = b + str(n % 2)
n = int(n / 2)
return b[::-1]
def d2b(n):
if n == 0:
return ''
@fmasanori
fmasanori / hfmix.pyw
Created November 28, 2013 21:27
Head First DJ Mix
from tkinter import *
from sound_panel import *
import pygame.mixer
import os
app=Tk()
app.title('Head First Mix')
mixer = pygame.mixer
mixer.pre_init(buffer = 300)
mixer.init()
@fmasanori
fmasanori / pdf2txt.py
Created August 9, 2017 00:25
pdf2txt
#!/usr/bin/env python
"""
Converts PDF text content (though not images containing text) to plain text, html, xml or "tags".
"""
import sys
import logging
import six
import pdfminer.settings
pdfminer.settings.STRICT = False