From 7eabead9a74438f85dc8bb662ca16fadb3766e00 Mon Sep 17 00:00:00 2001 From: Farhi Date: Wed, 29 Jan 2020 20:46:16 +0100 Subject: [PATCH] =?UTF-8?q?Transf=C3=A9rer=20les=20fichiers=20vers=20'prog?= =?UTF-8?q?ramme=20pour=20pc'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- programme pour pc/3ForAll.py | 111 +++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 programme pour pc/3ForAll.py diff --git a/programme pour pc/3ForAll.py b/programme pour pc/3ForAll.py new file mode 100644 index 0000000..80b7ef0 --- /dev/null +++ b/programme pour pc/3ForAll.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python3.6 +# -*- coding: utf-8 -*- +from bs4 import BeautifulSoup +import urllib3 +import requests +import socket +import serial +import time +import sys +import os +O=False +for i in range(400): + if O: + break + try: + arduino=serial.Serial("/COM"+str(i),timeout=1,baudrate=9600)#port de l'arduino à régler en fonction de celui que vous utilisez + O=True + except: + "" +print("connecté: /COM",i) +try: + # Python2 + from urllib2 import urlopen +except ImportError: + # Python3 + from urllib.request import urlopen +def web(url): + http = urllib3.PoolManager() + #print(url) + + try: + response = requests.get(url) + map_html = BeautifulSoup(response.content, "html.parser") + map_html=str(map_html) + map_html=map_html.replace("","") + map_html=map_html.replace("é","é") + except: + map_html = (urlopen(url).read()).decode() + return str(map_html) +def sep(texte): + lst2=["\n","\r","\t"] + #texte=texte.split("") + del a[0] + b=[] + for i in a: + d=i.split("<")[0] + if d!="": + if not d in lst2: + b.append(d) + + return b +def uni(lst): + a="" + for i in lst: + a=a+i + return a +def read(): + b=str(arduino.readline().decode('latin-1')) + b=b.replace("\x00","") + b=b.replace("^1","-") + b=b.replace("https:/w","https://w") + b=b.replace("¹","/") + return b +def write(txt): + arduino.write(str("000000"[:6-len(str(len(str(txt))))]+str(len(str(txt)))).encode()) + b=0 + while True: + a=read() + if a!="": + break + if b>3: + break + b=b+1 + time.sleep(0.5) + arduino.write(str(txt).encode()) + +while True: + a=read() + if a!="" and "&" in a: + a=a.split("&") + del a[0] + c="" + for i in a: + c=c+"&"+i + a=c + if "&vlc:" in a: + print(a) + a=a.replace("&vlc:","") + if "&URL:"in a: + a=a.replace("&URL:","") + b=web(a) + b=b.split("@") + time.sleep(1) + write("ok") + print("ok") + if "&PIC:"in a: + a=a.replace("&PIC:","") + a=int(a) + print(len(b[a])) + write(b[a]) + a="" + if "&web:" in a: + print(a) + a=a.replace("&web:","") + if "&URL:"in a: + a=a.replace("&URL:","") + b=uni(sep(web(a))) + time.sleep(1) + write(b) + print("ok")