Last active
December 28, 2018 17:06
-
-
Save rzdhop/ad4c56a6b77ee7c112599d19d781fb7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding:utf-8 | |
from math import sqrt | |
import matplotlib.pyplot as plt | |
from random import randint | |
import smtplib | |
import os | |
import subprocess | |
###################################################################################################################### | |
############################################ Fonction File management ################################################ | |
###################################################################################################################### | |
""" | |
r, pour une ouverture en lecture (READ). | |
w, pour une ouverture en écriture (WRITE), à chaque ouverture le contenu du fichier est écrasé. Si le fichier n'existe pas python le crée. | |
a, pour une ouverture en mode ajout à la fin du fichier (APPEND). Si le fichier n'existe pas python le crée. | |
b, pour une ouverture en mode binaire. | |
t, pour une ouverture en mode texte. | |
x, crée un nouveau fichier et l'ouvre pour écriture | |
""" | |
def logfile(): | |
check_dossier = os.path.exist("Config")#check si dossier exist | |
if check_dossier == False: | |
try: | |
os.mkdir("Config")#crée un dossier | |
except NameError: | |
os.makedirs("Config") | |
with open("Config/config.ini","a") as f: | |
f.write("CountX\n") | |
L=[] | |
with open("Config/config.ini","r") as f: | |
L = f.readlines() | |
attempt = len(L) | |
check_file = os.path.isfile("LogFile_Code_all.txt") | |
if check_file != True: | |
logfile = open("Config/LogFile_Code_all.txt","x") | |
logfile.write("----------------------------------------------\n\tLogFile by Rida\n\n Test numéros:{}\n\n----------------------------------------------\n".format(attempt)) | |
logfile.close() | |
else: | |
logfile = open("Config/LogFile_Code_all.txt","a") | |
logfile.write("\n\tLogFile by Rida\n\n Test numéros:{}\n\n----------------------------------------------\n".format(attempt)) | |
logfile.close() | |
###################################################################################################################### | |
############################################ Fonction OS/subprocess ################################################## | |
###################################################################################################################### | |
def Choix_OS_prompt(): | |
print("[1]OS\n[2]Subprocess\n") | |
choix_prompt = int(input(":")) | |
command = "cmd" | |
if choix_prompt==1: | |
os.system(command) | |
elif choix_prompt==2: | |
subprocess.Popen(command) | |
else: | |
print("Choix Invalid") | |
Start() | |
###################################################################################################################### | |
############################################ Fonction Mail ########################################################### | |
###################################################################################################################### | |
def login(mail,passwrd): | |
server.starttls() | |
server.login(mail, passwrd) | |
def envoie_mail(mail,destinataire,msg): | |
server.sendmail(mail, destinataire, msg) | |
server.quit() | |
def choix_Mail(): | |
server = smtplib.SMTP('smtp.gmail.com', 587) | |
mail = input("\n\nTappez votre mail :") | |
passwrd = input("\nTappez votre password:") | |
login(mail,passwrd) | |
msg = input("Votre message :\n") | |
destinataire = str(input("\n\nAdresse e-mal du destinataire:")) | |
envoie_mail(mail,destinataire,msg) | |
###################################################################################################################### | |
############################################ Fonction QR_Code ######################################################## | |
###################################################################################################################### | |
def QR_Code_manuel(ligne_manuel,colonne_manuel): | |
M =[] | |
L =[] | |
for k in range(ligne_manuel): | |
M = [randint(0,1) for _ in range(colonne_manuel)] | |
L.append(M) | |
plt.imshow(L,cmap='gray') | |
plt.show() | |
start() | |
def QR_Code_aleatoire(ligne_aleatoire,colonne_aleatoire): | |
M =[] | |
L =[] | |
for k in range(ligne_aleatoire): | |
M = [randint(0,1) for _ in range(colonne_aleatoire)] | |
L.append(M) | |
plt.imshow(L,cmap='gray') | |
plt.show() | |
start() | |
def choix_QR_code(QR_Code_manuel,QR_Code_aleatoire): | |
print("\n Mode : [1] manuel | [2] Aléatoire \n") | |
mode = int(input("Choisir l'option:")) | |
if mode == 1: | |
ligne_manuel = int(input("Choisi le nombre de ligne:")) | |
colonne_manuel = int(input("Choisi le nombre de colonne:")) | |
QR_Code_manuel(ligne_manuel,colonne_manuel) | |
elif mode==2: | |
ligne_aleatoire = randint(1,500) | |
colonne_aleatoire = randint(1,500) | |
QR_Code_aleatoire(ligne_aleatoire,colonne_aleatoire) | |
###################################################################################################################### | |
############################################ Fonction Calculs ######################################################## | |
###################################################################################################################### | |
def choix_calculs(): | |
choix_calculs_1 = int(input("[1]Addition\n[2]Multiplication\n[3]Racine carré\n[4]Division\n\t :")) | |
if choix_calculs_1==1: | |
addition_1 = int(input("on additionne\n :")) | |
addition_2 = int(input("et :")) | |
result_addition = addition_1 + addition_2 | |
print("le resultat est :{}".format(result_addition)) | |
start() | |
elif choix_calculs_1==2: | |
multiplication_1 = int(input("on multiplie\n :")) | |
multiplication_2 = int(input("et :")) | |
result_multiplication = multiplication_1 * multiplication_2 | |
print("le resultat de la multiplication est :{}".format(result_multiplication)) | |
start() | |
elif choix_calculs_1==3: | |
racine_1 = int(input("la racine de\n :")) | |
result_racine = sqrt(racine_1) | |
print("le resultat de la racine est :{}".format(result_racine)) | |
start() | |
elif choix_calculs_1==4: | |
division_1 = int(input("Division de\n :")) | |
division_2 = int(input("et:\n")) | |
result_division = division_1 / division_2 | |
result_reste = division_1 % division_2 | |
print("le resultat de la divition est :{} le reste est de:{}".format(result_division,result_reste)) | |
start() | |
else: | |
print("Choix Invalid: Tappez '1' pour Addition ou tappez '2'pour Multiplication\n") | |
###################################################################################################################### | |
############################################ Fonction Start ######################################################## | |
###################################################################################################################### | |
def start(): | |
logfile() | |
choix_1 = int(input("\n\nQue voulez-vous ? \n\t[1]Calculs \n\t[2]QR code \n\t[3]Mail(Pas Fini) \n\t[4]OS_prompt \n\t[99]Quit \n\t :")) | |
if choix_1==1: | |
choix_calculs() | |
elif choix_1==2: | |
choix_QR_code(QR_Code_manuel,QR_Code_aleatoire) | |
elif choix_1==3: | |
choix_Mail() | |
elif choix_1==4: | |
Choix_OS_prompt() | |
elif choix_1==99: | |
exit() | |
else: | |
print("Choix Invalid: Tappez '1' pour Calculs ou tappez '2' pour QR code\n") | |
start() | |
###################################################################################################################### | |
###################################################################################################################### | |
###################################################################################################################### | |
start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment