forked from sreelekhasuresh404/Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile Sharing App.py
More file actions
72 lines (51 loc) · 1.71 KB
/
Copy pathFile Sharing App.py
File metadata and controls
72 lines (51 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# import necessary modules
# for implementing the HTTP Web servers
import http.server
# provides access to the BSD socket interface
import socket
# a framework for network servers
import socketserver
# to display a Web-based documents to users
import webbrowser
# to generate qrcode
import pyqrcode
from pyqrcode import QRCode
# convert into png format
import png
# to access operating system control
import os
# assigning the appropriate port value
PORT = 8010
# this finds the name of the computer user
os.environ['USERPROFILE']
# changing the directory to access the files desktop
# with the help of os module
desktop = os.path.join(os.path.join(os.environ['USERPROFILE']),
'OneDrive')
os.chdir(desktop)
# creating a http request
Handler = http.server.SimpleHTTPRequestHandler
# returns, host name of the system under
# which Python interpreter is executed
hostname = socket.gethostname()
# finding the IP address of the PC
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
IP = "http://" + s.getsockname()[0] + ":" + str(PORT)
link = IP
# converting the IP address into the form of a QRcode
# with the help of pyqrcode module
# converts the IP address into a Qrcode
url = pyqrcode.create(link)
# saves the Qrcode inform of svg
url.svg("myqr.svg", scale=8)
# opens the Qrcode image in the web browser
webbrowser.open('myqr.svg')
# Creating the HTTP request and serving the
# folder in the PORT 8010,and the pyqrcode is generated
# continuous stream of data between client and server
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
print("Type this in your Browser", IP)
print("or Use the QRCode")
httpd.serve_forever()