Skip to content

Commit

Permalink
tabs -> spaces and added __main__
Browse files Browse the repository at this point in the history
  • Loading branch information
shreydan committed Apr 28, 2017
1 parent def3eaa commit 88625a4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 37 deletions.
14 changes: 7 additions & 7 deletions timymodule.py
Expand Up @@ -9,7 +9,7 @@

@timy.timer(ident = 'listcomp', loops = 1) # timy decorator
def listcomprehension(): # the function whose execution time is calculated.
li = [x for x in range(0,100000,2)]
li = [x for x in range(0,100000,2)]

listcomprehension()

Expand All @@ -29,12 +29,12 @@ def listcomprehension(): # the function whose execution time is calculated.
# to track specific instances in the program

def listcreator():
with timy.Timer() as timer:
li = []
for i in range(0,100000,2):
li.append(i)
if i == 50000:
timer.track('reached 50000')
with timy.Timer() as timer:
li = []
for i in range(0,100000,2):
li.append(i)
if i == 50000:
timer.track('reached 50000')

listcreator()

Expand Down
64 changes: 34 additions & 30 deletions xkcd_downloader.py
Expand Up @@ -14,33 +14,37 @@
import urllib.request
import os

# opens xkcd.com
try:
page = requests.get("https://www.xkcd.com")
except requests.exceptions.RequestException as e:
print (e)
exit()

# parses xkcd.com page
tree = html.fromstring(page.content)

# finds image src url
image_src = tree.xpath(".//*[@id='comic']/img/@src")[0]
image_src = "https:" + str(image_src)

# gets comic name from the image src url
comic_name = image_src.split('/')[-1]
comic_name = comic_name[:-4]

# save location of comic
comic_location = os.getcwd() + '/comics/'

# checks if save location exists else creates
if not os.path.exists(comic_location):
os.makedirs(comic_location)

# creates final comic location including name of the comic
comic_location = comic_location + comic_name

# downloads the comic
urllib.request.urlretrieve(image_src, comic_location)
def main():
# opens xkcd.com
try:
page = requests.get("https://www.xkcd.com")
except requests.exceptions.RequestException as e:
print (e)
exit()

# parses xkcd.com page
tree = html.fromstring(page.content)

# finds image src url
image_src = tree.xpath(".//*[@id='comic']/img/@src")[0]
image_src = "https:" + str(image_src)

# gets comic name from the image src url
comic_name = image_src.split('/')[-1]
comic_name = comic_name[:-4]

# save location of comic
comic_location = os.getcwd() + '/comics/'

# checks if save location exists else creates
if not os.path.exists(comic_location):
os.makedirs(comic_location)

# creates final comic location including name of the comic
comic_location = comic_location + comic_name

# downloads the comic
urllib.request.urlretrieve(image_src, comic_location)

if __name__ == "__main__":
main()

0 comments on commit 88625a4

Please sign in to comment.