ROS Code
 All Classes Namespaces Files Functions Variables
web.py
Go to the documentation of this file.
1 # Web modules
2 import webbrowser
3 import urllib
4 
5 # Generate And Run MailTo
6 
7 
8 def mailto(to, cc, bcc, subject, body, autorun=True):
9  mailurl = 'mailto:' + str(to)
10  if cc is None and bcc is None and subject is None and body is None:
11  if autorun is True:
12  webbrowser.open_new_tab(str(mailurl))
13  return str(mailurl)
14  mailurl += '?'
15  if cc is not None:
16  mailurl += 'cc=' + str(cc)
17  added = True
18  added = False
19  if bcc is not None:
20  if added is True:
21  mailurl += '&'
22  mailurl += 'bcc=' + str(cc)
23  added = True
24  if subject is not None:
25  if added is True:
26  mailurl += '&'
27  mailurl += 'subject=' + str(subject)
28  added = True
29  if body is not None:
30  if added is True:
31  mailurl += '&'
32  mailurl += 'body=' + str(body)
33  added = True
34  if autorun is True:
35  webbrowser.open_new_tab(str(mailurl))
36  else:
37  return mailurl
38 
39 
40 # Open A Link In A Web Browser
41 
42 
43 def openurl(url):
44  try:
45  webbrowser.open(url)
46  except webbrowser.Error:
47  raise RuntimeError('An Error Has Occured: Unable To Open URL (0017)')
48 
49 
50 # Open A Link In A New Window Of A Web Browser
51 
52 
53 def newwindow(url):
54  try:
55  webbrowser.open_new(url)
56  except webbrowser.Error:
57  raise RuntimeError('An Error Has Occured: Unable To Open URL (0017)')
58 
59 
60 # Open A Link In A New Tab Of A Web Browser
61 
62 
63 def newtab(url):
64  try:
65  webbrowser.open_new_tab(url)
66  except webbrowser.Error:
67  raise RuntimeError('An Error Has Occured: Unable To Open URL (0017)')
68 
69 
70 # Get The Name Of The Browser Currently Being Used
71 
72 
73 def getbrowser():
74  try:
75  webbrowser.get(using=None)
76  except BaseException:
77  return None
78 
79 
80 # Download A File
81 
82 
83 def filedownload(source, destination):
84  if not isempty(source):
85  if not isempty(destination):
86  try:
87  urllib.request.urlretrieve(source, destination)
88  except BaseException:
89  raise RuntimeError(
90  'An Error Has Occured: File Download Error (0010)')
91  else:
92  raise RuntimeError(
93  'An Error Has Occured: Source Or Destination Invalid (0011)')
94  else:
95  raise RuntimeError(
96  'An Error Has Occured: Source Or Destination Invalid (0011)')
def getbrowser
Definition: web.py:73
def openurl
Definition: web.py:43
def mailto
Definition: web.py:8
def isempty
Definition: main.py:476
def filedownload
Definition: web.py:83
def newtab
Definition: web.py:63
def newwindow
Definition: web.py:53