Skip to content

Commit 6eaeecc

Browse files
committed
Added some stuff.
1 parent a4cab9d commit 6eaeecc

File tree

5 files changed

+138
-0
lines changed

5 files changed

+138
-0
lines changed

Diff for: bmi.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import sys
2+
w=float(sys.argv[1])
3+
h=float(sys.argv[2])
4+
bmi = w/(h**2)
5+
print "%.2f" %bmi
6+
if bmi < 15: status = "Very severely underweight"; print status; exit(1)
7+
if bmi >= 15 and bmi <= 16: status = "Severely underweight"; print status; exit(1)
8+
if bmi > 16 and bmi <= 18.5: status = "Underweight"; print status; exit(1)
9+
if bmi > 18.5 and bmi <= 25: status = "Normal"; print status; exit(1)
10+
if bmi > 25 and bmi <= 30: status = "Overweight"; print status; exit(1)
11+
if bmi > 30 and bmi <= 35: status = "Moderately obese"; print status; exit(1)
12+
if bmi > 35 and bmi <= 40: status = "Severely obese"; print status; exit(1)
13+
if bmi > 40: status = "Very severely obese"; print status; exit(1)

Diff for: caesar.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import string, sys
2+
strr = sys.argv[1]
3+
caesar = string.maketrans(
4+
"ABCDEFGHIJKLMabcdefghijklmNOPQRSTUVWXYZnopqrstuvwxyz",
5+
"DEFGHIJKLMNOPdefghijklmnopQRSTUVWXYZABCqrstuvwxyzabc")
6+
print strr.translate(caesar)

Diff for: chess960.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
from random import shuffle
3+
pieces = ["♚", "♛", "♝", "♝", "♞", "♞", "♜", "♜"]
4+
for i in xrange(10): shuffle(pieces)
5+
for i in pieces: print i + " ",

Diff for: collatz_conjecture.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import sys
2+
from time import sleep
3+
class Unbuffered(object):
4+
def __init__(self, stream):
5+
self.stream = stream
6+
def write(self, data):
7+
self.stream.write(data)
8+
self.stream.flush()
9+
def __getattr__(self, attr):
10+
return getattr(self.stream, attr)
11+
sys.stdout = Unbuffered(sys.stdout)
12+
n=int(sys.argv[1])
13+
if n <= 1: print "n must be greater than 1."; exit(1)
14+
numbers=[]
15+
repeat=[4, 2, 4, 2]
16+
print "%s --> " %str(n),
17+
while n != 1:
18+
if n == 2: print "1"; exit(1)
19+
if n%2 == 0: n=n/2
20+
else: n=(n*3)+1
21+
print "%s --> " %(str(n)),
22+
numbers.append(n)
23+
sleep(0.01)

Diff for: pyweather.py

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import os, subprocess, json, sys, time
2+
from urllib2 import urlopen
3+
def getIP():
4+
IPAddress = urlopen('http://ip.42.pl/raw').read()
5+
os.system('wget http://ip-api.com/json/%s -qO .raw.userlocation.json' % (IPAddress))
6+
subprocess.Popen(['./parseJson.sh location'], shell = True)
7+
def get():
8+
global formatted_address, zipcode, iso_country_code, city
9+
lines = [line.rstrip('\n') for line in open('.userlocation.json')]
10+
for i, line in enumerate(lines):
11+
if i == 13:
12+
zipcode = line
13+
os.system('wget http://maps.googleapis.com/maps/api/geocode/json?address=%s -qO .googlemaps.json' % (zipcode))
14+
with open('.googlemaps.json') as data_file:
15+
data = json.load(data_file)
16+
formatted_address = data["results"][0]["formatted_address"]
17+
iso_country_code = data["results"][0]["address_components"][-1]["short_name"]
18+
city = data["results"][0]["address_components"][1]["long_name"]
19+
if iso_country_code == "US":
20+
state = data["results"][0]["address_components"][-2]["short_name"]
21+
def repl():
22+
global formatted_address, zipcode, iso_country_code, city, state
23+
os.system('wget http://maps.googleapis.com/maps/api/geocode/json?address=%s -qO .googlemaps.json' % (zipcode))
24+
with open('.googlemaps.json') as data_file:
25+
data = json.load(data_file)
26+
formatted_address = data["results"][0]["formatted_address"]
27+
city = data["results"][0]["address_components"][1]["long_name"]
28+
iso_country_code = data["results"][0]["address_components"][-1]["short_name"]
29+
if iso_country_code == "US":
30+
state = data["results"][0]["address_components"][-2]["short_name"]
31+
print "Address replaced with " + formatted_address + "."
32+
time.sleep(5)
33+
def check():
34+
yes = set(['yes','y', 'ye', ''])
35+
no = set(['no','n'])
36+
global zipcode
37+
print "Is this your location?: " + formatted_address
38+
sys.stdout.write("[y/n] ")
39+
response = raw_input()
40+
if (response in yes) == False and (response in no) == False:
41+
while 1:
42+
print "Try again."
43+
response = raw_input()
44+
if response in yes or response in no:
45+
break
46+
if response in yes:
47+
print "OK."
48+
autolocate_status = "correct"
49+
elif response in no:
50+
sys.stdout.write("Sorry about that - please enter your city's ZIP code. ")
51+
while 1:
52+
zipcode = raw_input()
53+
print "So your ZIP code is %s? [y/n]" % zipcode
54+
response_b = raw_input()
55+
if response_b in yes:
56+
print "Got it."
57+
repl()
58+
break
59+
if response_b in no:
60+
print "Please enter your ZIP code."; pass
61+
os.system('wget http://maps.googleapis.com/maps/api/geocode/json?address=%s -qO .googlemaps.json' % (zipcode))
62+
def getWeather():
63+
global zipcode, iso_country_code
64+
os.system('wget "http://api.openweathermap.org/data/2.5/weather?zip=' + zipcode + ',' + iso_country_code + '&units=imperial" -qO .weather.json')
65+
with open('.weather.json') as data_file:
66+
weather = json.load(data_file)
67+
errorcode = weather.get("cod")
68+
if errorcode == "404":
69+
print "Sorry! Your area couldn't be found using this API. Try searching for a more general area."
70+
exit(1)
71+
condition = weather["weather"][0]["main"]
72+
temp = json.dumps(weather["main"]["temp"])
73+
hitemp = json.dumps(weather["main"]["temp_max"])
74+
lotemp = json.dumps(weather["main"]["temp_min"])
75+
humidity = json.dumps(weather["main"]["humidity"])
76+
pressure = json.dumps(weather["main"]["pressure"])
77+
print "CONDITION %s " % condition
78+
print "TEMPERATURE %sF " % temp
79+
print "HIGH %sF " % hitemp
80+
print "LOW %sF " % lotemp
81+
print "HUMIDITY %s%% " % humidity
82+
print "PRESSURE %smbar" % pressure
83+
84+
######
85+
getIP()
86+
get()
87+
check()
88+
getWeather()
89+
90+
91+

0 commit comments

Comments
 (0)