File tree 3 files changed +52
-2
lines changed
3 files changed +52
-2
lines changed Original file line number Diff line number Diff line change 1
- /testing.py
1
+ /testing.py
2
+ * __pycache__
Original file line number Diff line number Diff line change 1
1
import platform
2
+ import pathlib
2
3
3
4
def get_os_name ():
4
5
os_name = platform .system () # Gets Operating System Name, for example: Windows, Linux
5
6
version = platform .release () # Gets Release Version of Operating System, for example: will return 10 if it is a Windows 10 machine
6
7
7
8
return os_name , version # return the info
8
9
10
+ def file_exists (path :str ):
11
+ """checks whether the following file exists. Use directory_exists to check if a directory exists"""
12
+
13
+ file = pathlib .Path (path )
14
+ if file .exists ():
15
+ return True
16
+ else :
17
+ return False
18
+
19
+
20
+ def directory_exists (path :str ):
21
+ """checks whether the following directory exists. Use file_exists to check if a file exists"""
22
+
23
+ file = pathlib .Path (path )
24
+ if file .is_dir ():
25
+ return True
26
+ else :
27
+ return False
28
+
Original file line number Diff line number Diff line change
1
+ from basic_functions import basic_functions
1
2
import socket
3
+ import requests
4
+ import urllib .request
5
+ import webbrowser
2
6
3
7
def get_private_ip ():
4
8
"""returns the Private ip address of the current device, May get the private ip for a virtualbox/vmware apdater if it exists on the system"""
@@ -12,6 +16,31 @@ def get_device_hostname():
12
16
"""returns the current Device Hostname"""
13
17
14
18
device_hostname = socket .gethostname ()
15
-
16
19
return device_hostname
17
20
21
+ def get_public_ip ():
22
+ """returns the Public Ip address of the current device."""
23
+
24
+ ip = requests .get ('https://api.ipify.org' ).content .decode ('utf8' )
25
+ return ip
26
+
27
+ def download_file (url :str ,file_name :str ,overwrite_file = False ):
28
+ """downloads a file from a url
29
+ Arguments:
30
+ url: url of where to download the file from
31
+ file_name: the name of the file after downloading
32
+ overwrite_file: replace the file if a file of the same name exists
33
+
34
+ """
35
+
36
+
37
+ if overwrite_file == False :
38
+ if basic_functions .file_exists (file_name ):
39
+ raise FileExistsError ("a file name already exists with the filename you provided since the overwrite_file argument is False. An error has been raised, Change it to True to overwrite that file." )
40
+ else :
41
+ urllib .request .urlretrieve (url = url ,filename = file_name )
42
+ else :
43
+ urllib .request .urlretrieve (url = url ,filename = file_name )
44
+
45
+ def open_url (url :str ):
46
+ webbrowser .open (url = url )
You can’t perform that action at this time.
0 commit comments