-
Notifications
You must be signed in to change notification settings - Fork 2
/
LinkValidation.py
64 lines (60 loc) · 2.2 KB
/
LinkValidation.py
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
## @file LinkValidation.py
#
# @brief this file contains the LinkValidation Class
#
# @author JunHao
#
# @section libraries_main Libraries/Modules
# - os standard library (https://docs.python.org/3/library/os.html)
# - access to os ping function command.
# - urllib.request standard library (https://docs.python.org/3/library/urllib.request.html)
# - access to urlopen function
# - UrlExtraction (local)
# - access to UrlExtraction class
# Imports
import os
import urllib.request
from UrlExtraction import UrlExtraction
## Documentation for a LinkValidation Class
# LinkValidation class checks if given link is supported
# also check if host system is online.
class LinkValidation(UrlExtraction):
"""! LinkValidation class
used to validate url links for youtube and twitter
"""
# __init__ is the constructor name for all classes
def __init__(self):
"""! LinkValidation class initializer
"""
#List of supported sites.
self.Sitelist = ["youtube", "twitter"]
#Check if URL is valid and site is supported
def UrlValidation(self, UserUrl):
"""! Check if Url is valid and site is supported.
@param UserUrl url to be checked
@return True or False
"""
sitename = self.getSiteName(UserUrl)
if sitename in self.Sitelist: #check if site is supported
try: #if URL can be opened than is valid
urllib.request.urlopen(UserUrl)
#print("URL is valid")
return True
except: #if URL cannot be opened this bypass error generation and just tell us link is invalid
#print("URL is invalid or internet is down")
return False
else:
return False
#Check if system is online
def InternetVaild(self):
"""! Check if system is online
@return pingstatus
"""
response = os.system("ping google.com")
if response == 0:
pingstatus = True
return pingstatus
else:
pingstatus = False
print("Network is down,Please check your internet connection")
return pingstatus