From 603eb66e3618bae04cc315e37f7acbd25a74da92 Mon Sep 17 00:00:00 2001 From: Wenjing Date: Sun, 20 Feb 2022 16:53:11 -0600 Subject: [PATCH 1/4] set up two requests --- issoverhead-start/config.py | 0 issoverhead-start/main.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 issoverhead-start/config.py create mode 100644 issoverhead-start/main.py diff --git a/issoverhead-start/config.py b/issoverhead-start/config.py new file mode 100644 index 0000000..e69de29 diff --git a/issoverhead-start/main.py b/issoverhead-start/main.py new file mode 100644 index 0000000..445d398 --- /dev/null +++ b/issoverhead-start/main.py @@ -0,0 +1,37 @@ +import requests +from datetime import datetime + +MY_LAT = 51.507351 # Your latitude +MY_LONG = -0.127758 # Your longitude + +response = requests.get(url="http://api.open-notify.org/iss-now.json") +response.raise_for_status() +data = response.json() + +iss_latitude = float(data["iss_position"]["latitude"]) +iss_longitude = float(data["iss_position"]["longitude"]) + +#Your position is within +5 or -5 degrees of the ISS position. + + +parameters = { + "lat": MY_LAT, + "lng": MY_LONG, + "formatted": 0, +} + +response = requests.get("https://api.sunrise-sunset.org/json", params=parameters) +response.raise_for_status() +data = response.json() +sunrise = int(data["results"]["sunrise"].split("T")[1].split(":")[0]) +sunset = int(data["results"]["sunset"].split("T")[1].split(":")[0]) + +time_now = datetime.now() + +#If the ISS is close to my current position +# and it is currently dark +# Then send me an email to tell me to look up. +# BONUS: run the code every 60 seconds. + + + From 14a4c9d84acd95dbad8beda6be0d52e9c3072681 Mon Sep 17 00:00:00 2001 From: Wenjing Date: Mon, 21 Feb 2022 22:00:21 -0600 Subject: [PATCH 2/4] Finished --- issoverhead-start/main.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/issoverhead-start/main.py b/issoverhead-start/main.py index 445d398..1a98b59 100644 --- a/issoverhead-start/main.py +++ b/issoverhead-start/main.py @@ -1,5 +1,7 @@ import requests from datetime import datetime +import smtplib +import time MY_LAT = 51.507351 # Your latitude MY_LONG = -0.127758 # Your longitude @@ -11,8 +13,7 @@ iss_latitude = float(data["iss_position"]["latitude"]) iss_longitude = float(data["iss_position"]["longitude"]) -#Your position is within +5 or -5 degrees of the ISS position. - +# Your position is within +5 or -5 degrees of the ISS position. parameters = { "lat": MY_LAT, @@ -28,10 +29,25 @@ time_now = datetime.now() -#If the ISS is close to my current position -# and it is currently dark -# Then send me an email to tell me to look up. + # BONUS: run the code every 60 seconds. +while True: + time.sleep(60) + # If the ISS is close to my current position + if MY_LONG - 5 <= iss_longitude <= MY_LONG + 5 and MY_LAT - 5 <= iss_latitude <= MY_LAT + 5: + # and it is currently dark + if time_now.hour > sunset or time_now.hour < sunrise: + # Then send me an email to tell me to look up. + with smtplib.SMTP('smtp.gmail.com') as connection: + connection.starttls() + connection.login(user='test0827111.gmail.com',password='Nihaoya123!') + connection.sendmail(from_addr='test0827111.gmail.com', + to_addrs='q564756917@yahoo.com', + msg='Subject: Look up!\n\nHey, look up now~') + + + + From db1ac067aa88b6d06aef36f71d389bcfde456a7a Mon Sep 17 00:00:00 2001 From: Wenjing Date: Tue, 22 Feb 2022 21:09:48 -0600 Subject: [PATCH 3/4] QUIZ APP upgrade --- quizzler-app-start/data.py | 114 +++++++++++++++++++++++++++ quizzler-app-start/images/false.png | Bin 0 -> 2871 bytes quizzler-app-start/images/true.png | Bin 0 -> 2565 bytes quizzler-app-start/main.py | 21 +++++ quizzler-app-start/question_model.py | 5 ++ quizzler-app-start/quiz_brain.py | 34 ++++++++ quizzler-app-start/ui.py | 70 ++++++++++++++++ 7 files changed, 244 insertions(+) create mode 100644 quizzler-app-start/data.py create mode 100644 quizzler-app-start/images/false.png create mode 100644 quizzler-app-start/images/true.png create mode 100644 quizzler-app-start/main.py create mode 100644 quizzler-app-start/question_model.py create mode 100644 quizzler-app-start/quiz_brain.py create mode 100644 quizzler-app-start/ui.py diff --git a/quizzler-app-start/data.py b/quizzler-app-start/data.py new file mode 100644 index 0000000..35724b9 --- /dev/null +++ b/quizzler-app-start/data.py @@ -0,0 +1,114 @@ +import requests + +PARAMETERS = { + 'amount': 10, + 'type': 'boolean' +} +response = requests.get(url='https://opentdb.com/api.php', params=PARAMETERS) +data = response.json() +question_data = data['results'] +# print(question_data) + + +# question_data = [ +# { +# "category": "Science: Computers", +# "type": "boolean", +# "difficulty": "medium", +# "question": "The HTML5 standard was published in 2014.", +# "correct_answer": "True", +# "incorrect_answers": [ +# "False" +# ] +# }, +# { +# "category": "Science: Computers", +# "type": "boolean", +# "difficulty": "medium", +# "question": "The first computer bug was formed by faulty wires.", +# "correct_answer": "False", +# "incorrect_answers": [ +# "True" +# ] +# }, +# { +# "category": "Science: Computers", +# "type": "boolean", +# "difficulty": "medium", +# "question": "FLAC stands for 'Free Lossless Audio Condenser'.", +# "correct_answer": "False", +# "incorrect_answers": [ +# "True" +# ] +# }, +# { +# "category": "Science: Computers", +# "type": "boolean", +# "difficulty": "medium", +# "question": "All program codes have to be compiled into an executable file in order to be run. This file can then be executed on any machine.", +# "correct_answer": "False", +# "incorrect_answers": [ +# "True" +# ] +# }, +# { +# "category": "Science: Computers", +# "type": "boolean", +# "difficulty": "easy", +# "question": "Linus Torvalds created Linux and Git.", +# "correct_answer": "True", +# "incorrect_answers": [ +# "False" +# ] +# }, +# { +# "category": "Science: Computers", +# "type": "boolean", +# "difficulty": "easy", +# "question": "The programming language 'Python' is based off a modified version of 'JavaScript'", +# "correct_answer": "False", +# "incorrect_answers": [ +# "True" +# ] +# }, +# { +# "category": "Science: Computers", +# "type": "boolean", +# "difficulty": "medium", +# "question": "AMD created the first consumer 64-bit processor.", +# "correct_answer": "True", +# "incorrect_answers": [ +# "False" +# ] +# }, +# { +# "category": "Science: Computers", +# "type": "boolean", +# "difficulty": "easy", +# "question": "'HTML' stands for Hypertext Markup Language.", +# "correct_answer": "True", +# "incorrect_answers": [ +# "False" +# ] +# }, +# { +# "category": "Science: Computers", +# "type": "boolean", +# "difficulty": "easy", +# "question": "In most programming languages, the operator ++ is equivalent to the statement '+= 1'.", +# "correct_answer": "True", +# "incorrect_answers": [ +# "False" +# ] +# }, +# { +# "category": "Science: Computers", +# "type": "boolean", +# "difficulty": "hard", +# "question": "The IBM PC used an Intel 8008 microprocessor clocked at 4.77 MHz and 8 kilobytes of memory.", +# "correct_answer": "False", +# "incorrect_answers": [ +# "True" +# ] +# } +# ] diff --git a/quizzler-app-start/images/false.png b/quizzler-app-start/images/false.png new file mode 100644 index 0000000000000000000000000000000000000000..904c76d8fd090e92beb696b0102529a83abe2628 GIT binary patch literal 2871 zcma)8XEYlO7Y^#RsZy&(tg0HJHA`!kNUbzATN{r$cl_ul8;bI*Owx%b?2o&r=qB?q9S)oUJ(Geks6pvkcqM2!)U4Gow&)!KQ@9a zdEm^&%AUJVP3B4WjQ+uMG>*Mn1=dMb6pS1o2{j_YcL>LWbvds3fZ5*J#<~d{6 z)UhjJ*pQ;J5O!-Ze#xrYP|^HhPhu2Sowx7>zNnU1l4{ZFh(Nu2qpRbA#|Q;JL+|D^ zdK6P<^RlnB(gr4VJ0U7bu~M-yo*~oAUc?|tA-gO0t_FGf>k#c8CTAb@EyHp$Nx6g{n{Ru)cTNB9zO+MhMlhYQPGI9l^n&?H z%q*t{C}+!N^V*`$#zqZkVPpu+;>IA^}06C2_5T$UD5srJR(Y({QY(u z-@lf?l-^?XdTt0sA8^Y1PoHGc@kQ{qTTefxJ|#re4_ERKqRA$!!RAi3n}&4=yEJg{ z-RPMc4NvrNx-G7m;qSIZ>*O5*>DxlbWmbMC5<)Fqw^gi^O)ieY3%PCM5{=;s5st94)8=6MBi?$unQJ5(nQ)kVt;|Amsh)?D}e=l@FB2lj#; zSFi^XK`X_A@bliSTJkS#*7K$~^_39K$;GDjk5Wfz7@5csj(K#Sdgt(2!aQj@WEJ_z z$=PPUl}%T)h`9aN{T&vv5rj8{E*$_kGH}@AgIai~RQ}j&qou5Ks?Y<9UPm0}9{%iu zJhegZ9Tir=9}aTOsQ}gOhX(uFU;27ZNH<$?NK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pB7CrbJ^ zf{4a&+8)+&lMfP*oE$OvfyLs)lxE*D1wX;_<#+M@Rt#|eJT)y`OW5wHthVBD>cg={ z#-+nt$p`$~6-b4}ZA->Nw&b_sSw;6~U5Z&ttQ}MFy{XsL22mFBE7D((`dZE#;$Y%++KQY&I zjBeXl{j&?XOzC1kg$-f zo&2K*Z^l1VZLqwp3QWHEXwb+nnfp>!o)uhC7FmZwiQS)7t?_z^Zq{9JBYk}cVB$L{c8V=9S8O!;a*I-qze>xfQTme9Eq^?txJW$0$B zzp+hiXE-=VF&pI~^D-R@)2^&Bw1+RWn0XAHM8mE-fb|^1dMiqH4aj9MBaxLzIJ*In zuHkxFMby-Hg{yHe2dkNCn)ZaUmdO6cqJ_`UDfcahbIGLzaCT!)C}Iz6Lia=&>28i- z*8WH_7{Y!nP&czM5+7z3@bFV?d7#Ykdt1I>Edt2+t#IK7@);I zA}ypJ>#ci3UxZzPQmU)TiI4A;dH>M&V&*dxl8vdjrka|_`T4-z1IA1SpT3a&jlXEV z8S7bstlhW^F;mE+{Ua(c3|ucCE#235rB+ZfyTkko>yZkjXBuS+1gJ*aBSeOY0 z8={iFlWiAES@R06s7R}YFbUm4#?mkMcd9q6qR%;QBAdq-vi;5~T1n#eW~D^cLsy%w z$;4(uwA6c_jkx|cW4O-h-1*MnHgmn=rl->JZjt`d56%NKk$|uuj#&nZwdI%nD-qWh z(#K~#(AQ2s3FanM`jt&*`)#GP9$?RV%+zTC!_4+*Zmt#gGiSs7Vg`DErBk{eNi*jq y?%k88d0{ITPmN%|D{jn5pSjRp0I-3nK1%oLtN#Fx$E!&I literal 0 HcmV?d00001 diff --git a/quizzler-app-start/images/true.png b/quizzler-app-start/images/true.png new file mode 100644 index 0000000000000000000000000000000000000000..79ca9a304fd32c09b0b2cd9bc70e0ef7e39e8011 GIT binary patch literal 2565 zcmb7G=R4es68>rD>W;`NM<!v7r_d{a^F|05IujYnqay8ySyiDapRd zAgvkzC|-HO;l|HQwKN2D9>5i3lob@DWx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f59k z@2N`34*j|z)Y(86EwSEWZWt??i zM6BYL!q$}7@-TAj0KT@tV5NFBl$GdZ&{WjnIl39~_^s?C6h_yOEqPbk7 zX@F+voM_W``C%@{pLY`nL?%&?#f)RS$_~ciXckl1W}fokZ}gSMle|AK5H&yd;+OWZ^|=rGT#V?w~9mDDisPKeCN4 z<|1CD6gxkm!Yop=4u^Gac(NP1od;MdeI)ulPOgIha?VjncS_yor%z1gzT zBq0vL|jV?)7P2dSU<#6FTY*qGr_#)VDgbD+ty`T*Phk;q(hK9NvNT!a*%JB}jS zez-YyQ3B@BZOWwo9GP7G@}I;wOc#l~V2Ws-sc(Nx1N;*{w-(|yp(TnZbscA>1+AMS zd5DO^MUe#pL<&%!9;Dh3{<7D;Z5UJ9O7OUrc4Bl-RjdI33t<*-VX6^SM#$pGZa`*P zLehz1Xt0#IV?QN;OAIhdJiL>ndsv7Z^IW#E2zUAP&5ml~_t2R4McbBIrRu|}daGgs z-E;4*StU*Wtez36>Y0-RI+d31`Q7lZAQQ zEfB5oc2S;2Y0v{P>EQOSl7#RGs@;{Pk8KFu-1-YUyAs8fYM)XmmB$@hD2IZzq_*^g zu&rPVc*whZq6$_#q_zfhNt?!?QBx4|7(y^d-rdjsprSgr8RO8s-g$vfI)v<&OEli& z^_@xlHlRpu@Twkj`uJ+3%IPnqnU^ExJCle}wXa0349ctPx9I(=VqS|FAH$3Kfr0H+ zehVHYIo$5Xr8+3G3iW|Wey?02Z}VtQt+6Kj`db0>^^-r!y267?yg!A8t-Z{1O7ceW zXYeb*7Pyjg)z>aLCK(Z&4Tm=O>Ippt7BOJPWrjgM=T+)s7LzpU&Se?aE+%ylzG_@m m%TxewjkS_u*ZhC&`VV^>RGNv=`(*Mb0q8t1)U4ESe)V6GaM-&5 literal 0 HcmV?d00001 diff --git a/quizzler-app-start/main.py b/quizzler-app-start/main.py new file mode 100644 index 0000000..7952584 --- /dev/null +++ b/quizzler-app-start/main.py @@ -0,0 +1,21 @@ +from question_model import Question +from data import question_data +from quiz_brain import QuizBrain +from ui import QuizInterface + +question_bank = [] +for question in question_data: + question_text = question["question"] + question_answer = question["correct_answer"] + new_question = Question(question_text, question_answer) + question_bank.append(new_question) + + +quiz = QuizBrain(question_bank) +quiz_ui = QuizInterface(quiz) + +# while quiz.still_has_questions(): +# quiz.next_question() + +# print("You've completed the quiz") +# print(f"Your final score was: {quiz.score}/{quiz.question_number}") diff --git a/quizzler-app-start/question_model.py b/quizzler-app-start/question_model.py new file mode 100644 index 0000000..b3d63d3 --- /dev/null +++ b/quizzler-app-start/question_model.py @@ -0,0 +1,5 @@ +class Question: + + def __init__(self, q_text, q_answer): + self.text = q_text + self.answer = q_answer diff --git a/quizzler-app-start/quiz_brain.py b/quizzler-app-start/quiz_brain.py new file mode 100644 index 0000000..688181a --- /dev/null +++ b/quizzler-app-start/quiz_brain.py @@ -0,0 +1,34 @@ +import html + + +class QuizBrain: + + def __init__(self, q_list): + self.question_number = 0 + self.score = 0 + self.question_list = q_list + self.current_question = None + + def still_has_questions(self): + return self.question_number < len(self.question_list) + + def next_question(self): + self.current_question = self.question_list[self.question_number] + self.question_number += 1 + q_text = html.unescape(self.current_question.text) + return f"Q.{self.question_number}: {q_text}" + # user_answer = input(f"Q.{self.question_number}: {q_text} (True/False): ") + # self.check_answer(user_answer) + + def check_answer(self, user_answer: str): + correct_answer = self.current_question.answer + if user_answer.lower() == correct_answer.lower(): + self.score += 1 + return True + # print("You got it right!") + else: + return False + # print("That's wrong.") + + # print(f"Your current score is: {self.score}/{self.question_number}") + # print("\n") diff --git a/quizzler-app-start/ui.py b/quizzler-app-start/ui.py new file mode 100644 index 0000000..dde945a --- /dev/null +++ b/quizzler-app-start/ui.py @@ -0,0 +1,70 @@ +from tkinter import * +from quiz_brain import QuizBrain +THEME_COLOR = "#375362" + + +class QuizInterface: + def __init__(self, quizbrain: QuizBrain): + self.quiz = quizbrain + + self.window = Tk() + self.window.title = 'Quiz APP' + self.window.config(padx=20, pady=20, bg=THEME_COLOR) + + self.canvas = Canvas(width=300, height=250, bg='white') + self.canvas.grid(column=0, row=1, columnspan=2, pady=20) + + self.text = self.canvas.create_text(150, 125, + width=280, + text='Some question texts', + fill=THEME_COLOR, + font=('Arial', 15, 'italic')) + + self.label = Label(text=f'Score: {self.quiz.score}', bg=THEME_COLOR, fg='white', font=('Arial', 12, 'italic')) + self.label.config(pady=10) + self.label.grid(column=1, row=0) + + t = PhotoImage(file='images/true.png') + self.button1 = Button(image=t, bg=THEME_COLOR, command=self.right) + self.button1.grid(column=0, row=2) + + f = PhotoImage(file='images/false.png') + self.button2 = Button(image=f, bg=THEME_COLOR, command=self.wrong) + self.button2.grid(column=1, row=2) + + self.get_question() + + self.window.mainloop() + + def get_question(self): + if self.quiz.still_has_questions(): + q_text = self.quiz.next_question() + self.canvas.itemconfig(self.text, text=q_text) + else: + self.canvas.config(bg='white') + self.canvas.itemconfig(self.text, text='You have reached the end of the questions~') + self.button1.config(state='disable') + self.button2.config(state='disable') + + def right(self): + is_right = self.quiz.check_answer('True') + self.give_feedback(is_right) + + def wrong(self): + is_right = self.quiz.check_answer('False') + self.give_feedback(is_right) + + def give_feedback(self,is_right): + if is_right: + print("you are right") + self.canvas.config(bg='green') + self.label.config(text=f"Score: {self.quiz.score}") + else: + print("you are wrong") + self.canvas.config(bg='red') + + self.window.after(1000, func=self.next_one) + + def next_one(self): + self.canvas.config(bg='white') + self.get_question() \ No newline at end of file From 9af04ca95b360af3b90408c3a66b96e95bc57d29 Mon Sep 17 00:00:00 2001 From: Wenjing Date: Wed, 23 Feb 2022 14:21:05 -0600 Subject: [PATCH 4/4] get 12 hours' weather info send alert if it will rain in 12 hours --- Rain Alert/main.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Rain Alert/main.py diff --git a/Rain Alert/main.py b/Rain Alert/main.py new file mode 100644 index 0000000..4ac1ec8 --- /dev/null +++ b/Rain Alert/main.py @@ -0,0 +1,39 @@ +import requests +import smtplib +import os + +PASSWORD = os.environ.get('PASS') + + +def send_alert(): + with smtplib.SMTP('smtp.gmail.com') as connection: + connection.starttls() + connection.login(user='test0827111@gmail.com', password=PASSWORD) + connection.sendmail(from_addr='test0827111@gmail.com', + to_addrs='q564756917@yahoo.com', + msg="Subject: Rain Alert\n\nBring an Umbrella~") + + +API_KEY = os.environ.get('APIKEY') + +PARAMETERS = { + "lon": -96.7836, + 'lat': 32.7668, + 'units': 'metric', + 'exclude': "current,minutely,daily", + 'appid': API_KEY +} +response = requests.get(url='https://api.openweathermap.org/data/2.5/onecall', params=PARAMETERS) +response.raise_for_status() +data = response.json() +print(data['hourly'][0]['weather'][0]['id']) + +for i in range(12): + id = data['hourly'][i]['weather'][0]['id'] + if id < 700: + send_alert() + print(f"{i} {id}, Bring an Umbrella") + break + + +