added comments and documentation

parent e38d0b75
......@@ -38,12 +38,14 @@ def cleanup(str):
return str
#this gets rid of the given things that all of them say false or true. It doesn't seem useful and it's just easier to ignore just get rid of it
#this just seems like useless junk everytime they pop up it's always false or always true for the given condition
def cleancontent(str):
str = str.replace("Publish event on the Calendar?: TRUE \n" , "")
str = str.replace("Performing any medical procedures?: FALSE \n" , "")
str = str.replace("Parking Needed?: FALSE \n" , "")
str = str[0:len(str) - 1]#this is here because there's always a \n at the end and it's pissing me off and is getting in the way
#this is here because there's always a \n at the end and it's pissing me off and is getting in the way
str = str[0:len(str) - 1]
return str
xmldoc = requests.get("http://25livepub.collegenet.com/calendars/events_all.xml") #grabs the xml from 25live
......@@ -54,54 +56,94 @@ xmldoc = cleanup(xmldoc.text)
soup = BeautifulSoup(xmldoc, "lxml") #creates soup of the xml
#print soup.prettify(), "\n\n"
#creates a list of all the entry tags from the xml
entries = soup.findAll('entry')
counter = 0
#creates a list of all the entry tags from the xml
entries = soup.findAll('entry')
#indexs an entry in the list of entries
for entry in entries:
#pulls up an entry in the list of entries, finds the title tag and .text deletes all xml tags and returns just the text
#pulls up an entry in the list of entries, finds the title tag and .text deletes all xml tags and returns just the text as a string
entry_title = entry.title.text
#print entry_title
#print ""
print "---------------------------------------------------start -----------------------------------------------------"
entry_content = entry.content.text
#check clearcontent function
#makes it easy to find as things may be unevenly spaced
entry_content = entry_content.replace("\n\n\n" , "\n")
entry_content = entry_content.replace("\n\n" , "\n")
#check clearcontent function
entry_content = cleancontent(entry_content)
#each piece of content may is seperated by a newline, entry_detailes creates a list
entry_detailes = entry_content.split("\n")
if (
#in entry detailes list normally the conditions go as follow
#[0] is the location
#[1] is the date
#[2] is the description
#either conditions follows
#[0] is date
#[0] is location
#[1] is date
#[0] is date
#[1] is description
#sometimes the location or description is not given; however, the location always goes before date and
#the description always follows the date. The date is always present. See examples above
#(A) if the location is not given then the date must be index [0]
#(B) if the length of the list = 1 and date is index [0] --> location not given & description is not given
#(C) if the length of the list = 2 and date is index [0] --> location not given but description is given at [1]
#(D) if the location is given then the date must be index [1]
#(E) if the length of the list = 2 and date is index [1] --> location is given at [0] but description is not given
#(F) if the length of the list = 3 and date is index [1] --> location is given at [0] and description is given at [2]
#the two if statements finds the date string. The date string always starts with
#Monday Tuesday Wednesday Thursday Friday Saturday Sunday or Ongoing and the date
#is always on either [0] or [1]
if (#see (A) above
entry_detailes[0][0:6] == "Monday" or
entry_detailes[0][0:7] == "Tuesday" or
entry_detailes[0][0:9] == "Wednesday" or
entry_detailes[0][0:8] == "Thursday" or
entry_detailes[0][0:6] == "Friday" or
entry_detailes[0][0:6] == "Friday" or
entry_detailes[0][0:8] == "Saturday" or
entry_detailes[0][0:6] == "Sunday" or
entry_detailes[0][0:7] == "Ongoing"):
if len(entry_detailes) == 2:
#See (B)
if len(entry_detailes) == 1:
location = "no location"
date = entry_detailes[0]
description = "no description"
#see (C)
elif len(entry_detailes) == 2:
location = "no location"
date = entry_detailes[0]
description = entry_detailes[1]
elif len(entry_detailes) == 1:
#This extra case was made because one entry had the description split into two by a
#newline so it registered as two descriptions making the length = 3
elif len(entry_detailes) == 3:
location = "no location"
date = entry_detailes[0]
description = "no description"
description = entry_detailes[1] + " " + entry_detailes[2]
#this will print if the code has failed to account for something in detailes, but it works as of December 26th 2017
else:
print "wut, this hsouldn't print plz halp, they probably changed the xml or something and means we need to update but if it work we should just ship it"
elif(
print "wut, this hsouldn't print plz halp,"
elif(#see (D) above
entry_detailes[1][0:6] == "Monday" or
entry_detailes[1][0:7] == "Tuesday" or
entry_detailes[1][0:9] == "Wednesday" or
......@@ -110,48 +152,45 @@ for entry in entries:
entry_detailes[1][0:8] == "Saturday" or
entry_detailes[1][0:6] == "Sunday" or
entry_detailes[1][0:7] == "Ongoing"):
#See (E)
if len(entry_detailes) == 2:
location = entry_detailes[0]
date = entry_detailes[1]
description = "no description given"
#See (F)
elif len(entry_detailes) == 3:
location = entry_detailes[0]
date = entry_detailes[1]
description = entry_detailes[2]
#This extra case was made because one entry had the description split into two by a
#newline so it registered as two descriptions making the length = 3
elif len(entry_detailes) == 4:
location = entry_detailes[0]
date = entry_detailes[1]
description = entry_detailes[2] + " " + entry_detailes[3]
#this will print if the code has failed to account for something in detailes
else:
print "wut, this hsouldn't print plz halp, they probably changed the xml or something and means we need to update but if it work we should just ship it"
print counter
print len(entry_detailes)
if counter == 36:
print entry_detailes#idk what going on with entry 36, drama department doin something weird and it shouldn't work but it does idk
counter += 1
print "wut, this hsouldn't print plz halp"
#this will print if the above if statements failed to find the date block
else:
print "if this prints there is something wrong please don't show up"
print "-----------------------------------------------------------------------------"
print location
print date
print description
print "----------------------------------------------------------------------------"
#27
'''
#just use as needed
content = entries[37].content.text
content = content.replace("\n\n" , "\n")
content = content.replace("\n\n\n" , "\n")
#content = cleancontent(content)
content = cleancontent(content)
#print content
detailes = content.split("\n")
print detailes[0]
print detailes[1]
print detailes[2]
'''
\ No newline at end of file
#everything in the house is fuzzy
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment