Transférer les fichiers vers 'programme pour pc'

This commit is contained in:
Farhi 2020-01-29 20:46:16 +01:00
parent 999020e590
commit 7eabead9a7
1 changed files with 111 additions and 0 deletions

View File

@ -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("</string>","")
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("<body")[1]
a=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")