Skip to content

Commit 5299455

Browse files
author
cuichao
committed
Merge remote-tracking branch 'upstream/master'
2 parents dd83c43 + 6311956 commit 5299455

9 files changed

+118
-27
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,5 @@ In the scripts the comments etc are lined up correctly when they are viewed in [
6060
- `Google_News.py` - Uses BeautifulSoup to provide Latest News Headline along with news link.
6161

6262
- `cricket_live_score` - Uses BeautifulSoup to provide live cricket score.
63+
64+
- `youtube.py` - Takes input a song name and fetches the youtube url of best matching song and plays it.

batch_file_rename.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
once you pass the current and new extensions
77
'''
88

9-
__author__ = 'Craig Richards'
9+
__author__ = 'Craig Richards'
1010
__version__ = '1.0'
1111

1212
import os
13-
import sys
1413
import argparse
1514

1615
def batch_rename(work_dir, old_ext, new_ext):
@@ -21,14 +20,13 @@ def batch_rename(work_dir, old_ext, new_ext):
2120
# files = os.listdir(work_dir)
2221
for filename in os.listdir(work_dir):
2322
# Get the file extension
24-
file_ext = os.path.splitext(filename)[1]
23+
split_file = os.path.splitext(filename)
24+
file_ext = split_file[1]
2525
# Start of the logic to check the file extensions, if old_ext = file_ext
2626
if old_ext == file_ext:
2727
# Returns changed name of the file with new extention
28-
name_list=list(filename)
29-
name_list[len(name_list)-len(old_ext):]=list(new_ext)
30-
newfile=''.join(name_list)
31-
28+
newfile = split_file[0] + new_ext
29+
3230
# Write the files
3331
os.rename(
3432
os.path.join(work_dir, filename),
@@ -54,8 +52,12 @@ def main():
5452
work_dir = args['work_dir'][0]
5553
# Set the variable old_ext with the second argument passed
5654
old_ext = args['old_ext'][0]
55+
if old_ext[0] != '.':
56+
old_ext = '.' + old_ext
5757
# Set the variable new_ext with the third argument passed
5858
new_ext = args['new_ext'][0]
59+
if new_ext[0] != '.':
60+
new_ext = '.' + new_ext
5961

6062
batch_rename(work_dir, old_ext, new_ext)
6163

check_input.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
def get_user_input(start,end):
22

3-
testcase = False
4-
while testcase == False:
3+
while (1):
54
try:
65
userInput = int(input("Enter Your choice: "))
7-
if userInput > 6 or userInput < 1:
6+
if userInput > end or userInput < start:
87
print("Please try again.")
9-
testcase = False
108
else:
119
return userInput
1210

@@ -16,8 +14,6 @@ def get_user_input(start,end):
1614

1715
x = get_user_input(1,6)
1816
print(x)
19-
20-
2117
###Asks user to enter something, ie. a number option from a menu.
2218
###While type != interger, and not in the given range,
2319
###Program gives error message and asks for new input.

daily_checks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def print_docs(): # Function to print the daily checks automatically
3333
subprocess.Popen(["C:\\Program Files (x86)\Microsoft Office\Office14\winword.exe", "P:\\\\Documentation\\Daily Docs\\Back office Daily Checks.doc", "/mFilePrintDefault", "/mFileExit"]).communicate()
3434

3535

36-
def putty_sessions(): # Function to load the putty sessions I need
36+
def putty_sessions(conffilename): # Function to load the putty sessions I need
3737
for server in open(conffilename): # Open the file server_list.txt, loop through reading each line - 1.1 -Changed - 1.3 Changed name to use variable conffilename
3838
subprocess.Popen(('putty -load '+server)) # Open the PuTTY sessions - 1.1
3939

@@ -63,7 +63,7 @@ def main():
6363
filename, "ran at", strftime("%Y-%m-%d %H:%M:%S"), "on",platform.node(), "run from",os.getcwd())
6464

6565
print_docs() # Call the print_docs function
66-
putty_sessions() # Call the putty_session function
66+
putty_sessions(conffilename) # Call the putty_session function
6767
rdp_sessions() # Call the rdp_sessions function
6868
euroclear_docs() # Call the euroclear_docs function
6969

dice_rolling_simulator.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#Made on May 27th, 2017
22
#Made by SlimxShadyx
33
#Editted by CaptMcTavish, June 17th, 2017
4+
#Comments edits by SlimxShadyx, August 11th, 2017
45

56
#Dice Rolling Simulator
67

@@ -9,15 +10,19 @@
910
global user_exit_checker
1011
user_exit_checker="exit"
1112

13+
#Our start function (What the user will first see when starting the program)
1214
def start():
1315
print "Welcome to dice rolling simulator: \nPress Enter to proceed"
1416
raw_input(">")
15-
17+
18+
#Starting our result function (The dice picker function)
1619
result()
1720

21+
#Our exit function (What the user will see when choosing to exit the program)
1822
def bye():
1923
print "Thanks for using the Dice Rolling Simulator! Have a great day! =)"
2024

25+
#Result function which is our dice chooser function
2126
def result():
2227

2328
#user_dice_chooser No idea how this got in here, thanks EroMonsterSanji.
@@ -27,7 +32,8 @@ def result():
2732
user_dice_chooser = raw_input(">")
2833

2934
user_dice_chooser = int(user_dice_chooser)
30-
35+
36+
#Below is the references to our dice functions (Below), when the user chooses a dice.
3137
if user_dice_chooser == 6:
3238
dice6()
3339

@@ -36,16 +42,20 @@ def result():
3642

3743
elif user_dice_chooser == 12:
3844
dice12()
39-
45+
46+
#If the user doesn't choose an applicable option
4047
else:
4148
print "\r\nPlease choose one of the applicable options!\r\n"
4249
result()
4350

4451

52+
#Below are our dice functions.
4553
def dice6():
54+
#Getting a random number between 1 and 6 and printing it.
4655
dice_6 = random.randint(1,6)
4756
print "\r\nYou rolled a " + str(dice_6) + "!\r\n"
48-
57+
58+
#Checking if the user would like to roll another die, or to exit the program
4959
user_exit_checker_raw = raw_input("\r\nIf you want to roll another die, type [roll]. To exit, type [exit].\r\n?>")
5060
user_exit_checker = (user_exit_checker_raw.lower())
5161
if user_exit_checker=="roll":
@@ -74,4 +84,6 @@ def dice12():
7484
start()
7585
else:
7686
bye()
87+
88+
#Actually starting the program now.
7789
start()

meme_maker.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
def input_par():
77
print('Enter the text to insert in image: ')
88
text = str(input())
9-
print('Enter the desired size: ')
9+
print('Enter the desired size of the text: ')
1010
size = int(input())
1111
print('Enter the color for the text(r, g, b): ')
1212
color_value = [int(i) for i in input().split(' ')]
@@ -22,14 +22,20 @@ def main():
2222

2323
print(image_file.size)
2424
text, size, color_value = input_par()
25-
25+
26+
#Font path is given as -->( " Path to your desired font " )
2627
font = ImageFont.truetype("C:\\Windows\\Fonts\\Arial.ttf", size=size)
2728

28-
# Clean the background noise, if color != white, then set to black.
29-
# change with your color
30-
for y in range(100):
31-
for x in range(100):
32-
pixdata[x, y] = (255, 255, 255, 255)
29+
#If the color of the text is not equal to white,then change the background to be white
30+
if((color_value[0] and color_value[1] and color_value[2])!=255):
31+
for y in range(100):
32+
for x in range(100):
33+
pixdata[x, y] = (255, 255, 255, 255)
34+
#If the text color is white then the background is said to be black
35+
else:
36+
for y in range(100):
37+
for x in range(100):
38+
pixdata[x, y] = (0,0, 0, 255)
3339
image_file.show()
3440

3541
# Drawing text on the picture

ping_servers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import subprocess # Load the Library Module
1313
import sys # Load the Library Module
1414

15+
filename = sys.argv[0] # Sets a variable for the script name
1516
if '-h' in sys.argv or '--h' in sys.argv or '-help' in sys.argv or '--help' in sys.argv: # Help Menu if called
1617
print '''
1718
You need to supply the application group for the servers you want to ping, i.e.
@@ -45,7 +46,6 @@
4546
elif 'bromley' in sys.argv: # Else if the argument passed is bromley
4647
site = 'bromley' # Set the variable site to bromley
4748

48-
filename = sys.argv[0] # Sets a variable for the script name
4949
logdir = os.getenv("logs") # Set the variable logdir by getting the OS environment logs
5050
logfile = 'ping_' + appgroup + '_' + site + '.log' # Set the variable logfile, using the arguments passed to create the logfile
5151
logfilename = os.path.join(logdir, logfile) # Set the variable logfilename by joining logdir and logfile together

prison_break_scrapper.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
Scrapper for downloading prison break
3+
series from an open server and putting them in a designated folder.
4+
"""
5+
import requests as req
6+
from bs4 import BeautifulSoup as bs
7+
import os
8+
import subprocess
9+
10+
11+
BASE_URL = 'http://dl.funsaber.net/serial/Prison%20Break/season%20'
12+
13+
14+
def download_files(links, idx):
15+
for link in links:
16+
subprocess.call([
17+
"aria2c",
18+
"-s",
19+
"16",
20+
"-x",
21+
"16",
22+
"-d",
23+
"season"+str(idx),
24+
link
25+
])
26+
27+
28+
def main():
29+
for i in range(1,5):
30+
r = req.get(BASE_URL+str(i)+'/1080/')
31+
soup = bs(r.text, 'html.parser')
32+
link_ = []
33+
for link in soup.find_all('a'):
34+
if '.mkv' in link.get('href'):
35+
link_.append(BASE_URL+str(i)+'/1080/'+link.get('href'))
36+
if not os.path.exists('season'+str(i)):
37+
os.makedirs('season'+str(i))
38+
download_files(link_, i)
39+
40+
41+
42+
if __name__ == '__main__':
43+
main()

youtube.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'''
2+
3+
Author: Abhinav Anand
4+
git: github.com/ab-anand
5+
mail: abhinavanand1905@gmail.com
6+
Requirements: requests, BeautifulSoup
7+
8+
'''
9+
import os
10+
import webbrowser
11+
12+
import requests
13+
from bs4 import BeautifulSoup
14+
15+
headers = {
16+
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36'}
17+
query = input('Enter the song to be played: ')
18+
query = query.replace(' ', '+')
19+
20+
# search for the best similar matching video
21+
url = 'https://www.youtube.com/results?search_query=' + query
22+
source_code = requests.get(url, headers=headers, timeout=15)
23+
plain_text = source_code.text
24+
soup = BeautifulSoup(plain_text, "html.parser")
25+
26+
# fetches the url of the video
27+
songs = soup.findAll('div', {'class': 'yt-lockup-video'})
28+
song = songs[0].contents[0].contents[0].contents[0]
29+
link = song['href']
30+
webbrowser.open('https://www.youtube.com' + link)

0 commit comments

Comments
 (0)