File tree Expand file tree Collapse file tree 1 file changed +36
-3
lines changed
Expand file tree Collapse file tree 1 file changed +36
-3
lines changed Original file line number Diff line number Diff line change 11#!/usr/bin/env python3
22
3+ import sys
4+ from datetime import datetime
35from pathlib import Path
4- from pyqrcode import QRCode
6+
7+ try :
8+ from pyqrcode import QRCode
9+ except ImportError :
10+ print ("pyqrcode module not found. Install it with 'python -m pip install pyqrcode pypng'" )
11+ sys .exit (1 )
512
613home = str (Path .home ())
14+ downloads = Path (f"{ home } /Downloads" )
15+ timestamp = datetime .now ().strftime ("%Y%m%d%H%M%S" )
16+
17+ if len (sys .argv ) == 2 and sys .argv [1 ].startswith ("http" ):
18+ url = QRCode (sys .argv [1 ])
19+ else :
20+ url = QRCode ("https://github.com/pythoninthegrass/python_template" )
21+
22+
23+ def check_file ():
24+ """
25+ Check if QR code already exists in ~/Downloads folder.
26+ If it does, rename it with a timestamp.
27+ """
28+ if Path (f"{ home } /Downloads/qr.png" ).exists ():
29+ print ("QR code already exists in ~/Downloads" )
30+ new_file_name = Path (f"{ downloads } /qr_{ timestamp } .png" )
31+ Path (f"{ downloads } /qr.png" ).rename (new_file_name )
32+ print (f"QR code copied to Downloads folder as 'qr_{ timestamp } .png'" )
33+
34+
35+ def main ():
36+ check_file ()
37+ url .png (Path (f"{ home } /Downloads/qr.png" ), scale = 8 )
38+ print ("QR code saved to Downloads folder as 'qr.png'" )
39+
740
8- url = QRCode ( "https://github.com/pythoninthegrass/python_template" )
9- url . png ( Path ( f" { home } /Downloads/repo.png" ), scale = 8 )
41+ if __name__ == "__main__" :
42+ main ( )
You can’t perform that action at this time.
0 commit comments