Skip to content

Commit b384471

Browse files
A lot of comics
1 parent 247e4d8 commit b384471

File tree

1,198 files changed

+139
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,198 files changed

+139
-2
lines changed

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"python.pythonPath": "/usr/bin/python3.5",
3+
"python.linting.enabled": false
4+
}
Binary file not shown.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import time
2+
3+
def calcProd():
4+
# Calculate the product of first 100,000 numbers
5+
product=1
6+
for i in range(1,100000):
7+
product=product*i
8+
return product
9+
10+
startTime=time.time()
11+
prod=calcProd()
12+
endTime=time.time()
13+
print("The result is %s digits long."%(len(str(prod))))
14+
print('Took %s seconds to calculate.' % (endTime - startTime))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#! /usr/bin/python3.5
2+
3+
"""
4+
5+
Author: Samrat Banerjee
6+
Dated: 08/09/2018
7+
Description: Project: A simple countdown script.
8+
9+
"""
10+
11+
import time, subprocess,webbrowser
12+
13+
timeLeft=60
14+
15+
while timeLeft>0:
16+
print(timeLeft,end=' ')
17+
time.sleep(1)
18+
timeLeft=timeLeft-1
19+
20+
# At the end of the countdown, play a sound file.
21+
webbrowser.open("https://www.rediff.com/")
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#! /usr/bin/python3.5
2+
3+
"""
4+
5+
Author: Samrat Banerjee
6+
Dated: 08/09/2018
7+
Description: Project: Downloads XKCD comics using multiple threads.
8+
9+
"""
10+
11+
import requests,os,bs4,threading
12+
13+
os.makedirs('xkcd', exist_ok=True) # store comics in ./xkcd
14+
15+
def downloadXkcd(startComic,endComic):
16+
for urlNumber in range(startComic, endComic):
17+
# Download the page
18+
print('Downloading page http://xkcd.com/%s...' %(urlNumber))
19+
res = requests.get('http://xkcd.com/%s' % (urlNumber))
20+
res.raise_for_status()
21+
22+
soup=bs4.BeautifulSoup(res.text)
23+
24+
# Find the url of the comic image
25+
comicElem=soup.select('#comic img')
26+
if comicElem==[]:
27+
print('Could not find comic image.')
28+
else:
29+
comicURL='https:' + comicElem[0].get('src')
30+
31+
# Download the image
32+
print("Downloading image %s..."%(comicURL))
33+
res=requests.get(comicURL)
34+
res.raise_for_status()
35+
36+
# Save the image to ./xkcd
37+
imageFile=open(os.path.join('xkcd',os.path.basename(comicURL)),'wb')
38+
for chunk in res.iter_content(100000):
39+
imageFile.write(chunk)
40+
imageFile.close()
41+
42+
43+
# Create and start the Thread objects.
44+
downloadThreads = [] # a list of all the Thread objects
45+
for i in range(0, 1400, 100): # loops 14 times, creates 14 threads
46+
downloadThread = threading.Thread(target=downloadXkcd, args=(i, i + 99))
47+
downloadThreads.append(downloadThread)
48+
downloadThread.start()
49+
50+
# Wait for all threads to end.
51+
for downloadThread in downloadThreads:
52+
downloadThread.join()
53+
print('Done.')
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#! /usr/bin/python3.5
2+
3+
4+
"""
5+
6+
Author: Samrat Banerjee
7+
Dated: 08/09/2018
8+
Description: Project: A simple stopwatch program.
9+
10+
"""
11+
12+
import time
13+
14+
# Display the program's instructions.
15+
print('Press ENTER to begin. Afterwards, press ENTER to "click" the stopwatch. Press Ctrl-C to quit.')
16+
input() # press Enter to begin
17+
print('Started.')
18+
startTime = time.time() # get the first lap's start time
19+
lastTime = startTime
20+
lapNum = 1
21+
22+
# Start tracking the lap times.
23+
try:
24+
while True:
25+
input()
26+
lapTime=round(time.time()-lastTime,2)
27+
totalTime=round(time.time()-startTime,2)
28+
print('Lap #%s: %s (%s)'%(lapTime,totalTime,lapTime),end=' ')
29+
lapNum+=1
30+
lastTime=time.time() # reset the last lap time
31+
except KeyboardInterrupt:
32+
# Handle the Ctrl-C exception to keep its error message from displaying.
33+
print('\nDone.')
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import threading, time
2+
3+
print('Start of program.')
4+
5+
def takeANap():
6+
time.sleep(5)
7+
print('Wake up!')
8+
9+
threadObj = threading.Thread(target=takeANap)
10+
threadObj.start()
11+
12+
print('End of program.')
8.51 KB
66.7 KB
90 KB

0 commit comments

Comments
 (0)