Skip to content
Open

tp #5

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tutu
  • Loading branch information
armandfou committed Sep 8, 2024
commit eae5272483ded608753408d0f26b0b84d5e2ae76
25 changes: 25 additions & 0 deletions src/05 Play the Waiting Game/my_waiting_game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import time

def waiting_game():
print("Your target time is 4 seconds")
x = input("---Press Enter to Begin--")
end = 0
print("x = " , x)
if (x != None):
start = time.time()
y = input("---Press Enter to Begin--")
print("start ", start)
print("x = " , x)
if (y != None):
end = time.time()
print("end ", end)
print("Elapsed time: " , abs(round((end - start) *1000) /1000)," seconds")
if ((end - start) >4):
s ="seconds too slow"
else:
s = "seconds too fast"
print("(",
abs(4 - round((end - start) *1000) /1000),
s," )" )

waiting_game()
13 changes: 13 additions & 0 deletions src/06 Save a Dictionary/my_dictionary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import json
def save_dict( dict,filePath):
with open(filePath, "w") as outfile:
json.dump(dict, outfile)
outfile.close()
def load_dict(filePath):
with open(filePath, "r") as outfile:
jsonString = outfile.read()
return json.loads(jsonString)
test_dict = {1: 'a', 2: 'b', 3: 'c'}
save_dict(test_dict, 'test_dict.pickle')
recovered = load_dict('test_dict.pickle')
print(recovered)
16 changes: 16 additions & 0 deletions src/07 Schedule a Function/my_schedule_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import sched
import time
from datetime import datetime


def schedule_function(event_time, function, *args):
scheduler = sched.scheduler(time.time, time.sleep)
scheduler.enterabs( event_time.timestamp(), 1, function, args)
scheduler.run()



def hello():
print("ggggggggggggggg")

schedule_function(datetime(2024, 9, 8, 0, 28), hello, None)
20 changes: 20 additions & 0 deletions src/08 Send an Email/my_send_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import smtplib

# Import the email modules we'll need
from email.message import EmailMessage

# Open the plain text file whose name is in textfile for reading.
def send_mail(receiverAdress, subject, content):
msg = EmailMessage()
msg.set_content(content)
sender = "armand.fouquiau@orange.fr"
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = receiverAdress
with smtplib.SMTP_SSL('smtp.orange.fr', 465) as smtp_server:
smtp_server.login(sender, "")
smtp_server.sendmail(sender,receiverAdress, msg.as_string())



send_mail('armand.fouquiau@orange.fr', 'Notification', 'Everything is awesome!')
1 change: 1 addition & 0 deletions test_dict.pickle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"1": "a", "2": "b", "3": "c"}