Skip to content

Commit dd83c43

Browse files
authored
Merge pull request #1 from geekcomputers/master
update codes
2 parents e8e8108 + 2f5c407 commit dd83c43

Some content is hidden

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

68 files changed

+2300
-331
lines changed

4 Digit Number Combinations.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# ALL the combinations of 4 digit combo
2+
def FourDigitCombinations():
3+
numbers=[]
4+
for code in range(10000):
5+
code=str(code).zfill(4)
6+
print code,
7+
numbers.append(code)

CountMillionCharacter.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
import pprint
2-
info = '''SCENE I. Yorkshire. Gaultree Forest.
1+
'''Simple million word count program.
2+
main idea is Python pairs words
3+
with the number of times
4+
that number appears in the triple quoted string.
5+
Credit to William J. Turkel and Adam Crymble for the word
6+
frequency code used below. I just merged the two ideas.
7+
'''
38

9+
wordstring = '''SCENE I. Yorkshire. Gaultree Forest.
410
Enter the ARCHBISHOP OF YORK, MOWBRAY, LORD HASTINGS, and others
511
ARCHBISHOP OF YORK
612
What is this forest call'd?
@@ -28,7 +34,6 @@
2834
Thus do the hopes we have in him touch ground
2935
And dash themselves to pieces.
3036
Enter a Messenger
31-
3237
HASTINGS
3338
Now, what news?
3439
Messenger
@@ -42,7 +47,6 @@
4247
ARCHBISHOP OF YORK
4348
What well-appointed leader fronts us here?
4449
Enter WESTMORELAND
45-
4650
MOWBRAY
4751
I think it is my Lord of Westmoreland.
4852
WESTMORELAND
@@ -225,7 +229,6 @@
225229
ARCHBISHOP OF YORK
226230
My lord, we will do so.
227231
Exit WESTMORELAND
228-
229232
MOWBRAY
230233
There is a thing within my bosom tells me
231234
That no conditions of our peace can stand.
@@ -278,7 +281,6 @@
278281
Be it so.
279282
Here is return'd my Lord of Westmoreland.
280283
Re-enter WESTMORELAND
281-
282284
WESTMORELAND
283285
The prince is here at hand: pleaseth your lordship
284286
To meet his grace just distance 'tween our armies.
@@ -287,10 +289,12 @@
287289
ARCHBISHOP OF YORK
288290
Before, and greet his grace: my lord, we come.
289291
Exeunt'''
290-
count = { }
291-
for character in info.upper():
292-
count.setdefault(character, 0)
293-
count[character] = count[character]+1
294292

295-
value = pprint.pformat(count)
296-
print(value)
293+
wordlist = wordstring.split()
294+
295+
wordfreq = [wordlist.count(w) for w in wordlist]
296+
297+
print("String\n {} \n".format(wordstring))
298+
print("List\n {} \n".format(str(wordlist)))
299+
print("Frequencies\n {} \n".format(str(wordfreq)))
300+
print("Pairs\n {}".format(str(list(zip(wordlist, wordfreq)))))

CountMillionCharacters-2.0.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""Get the number of each character in any given text.
2+
3+
Inputs:
4+
A txt file -- You will be asked for an input file. Simply input the name
5+
of the txt file in which you have the desired text.
6+
7+
"""
8+
9+
import pprint
10+
import collections
11+
12+
13+
def main():
14+
15+
file_input = input('File Name: ')
16+
17+
with open(file_input, 'r') as info:
18+
count = collections.Counter(info.read().upper())
19+
20+
value = pprint.pformat(count)
21+
print(value)
22+
23+
24+
if __name__ == "__main__":
25+
main()
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import sys
2+
3+
4+
def countchars(filename):
5+
count = {}
6+
7+
with open(filename) as info: # inputFile Replaced with filename
8+
readfile = info.read()
9+
for character in readfile.upper():
10+
count[character] = count.get(character, 0) + 1
11+
12+
return count
13+
14+
if __name__ == '__main__':
15+
if sys.version_info.major >= 3: # if the interpreter version is 3.X, use 'input',
16+
input_func = input # otherwise use 'raw_input'
17+
else:
18+
input_func = raw_input
19+
20+
inputFile = input_func("File Name : ")
21+
print(countchars(inputFile))
Binary file not shown.

Google Image Downloader/create_dir.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/python3
2+
3+
"""
4+
Code to directly use in file to
5+
create directory in home location
6+
7+
Note:- I Have used python package so if you want
8+
to create in the main directory of your project use
9+
pardir+"\\"+name in functions
10+
11+
All the folder operations are done on home
12+
project directory.
13+
"""
14+
15+
from shutil import copytree
16+
from shutil import move
17+
from os import chdir
18+
from os.path import exists
19+
from os.path import pardir
20+
from os import makedirs
21+
from os import removedirs
22+
from os import rename
23+
24+
25+
# Creates a directory
26+
def create_directory(name):
27+
if exists(pardir+"\\"+name):
28+
print('Folder already exists... Cannot Overwrite this')
29+
else:
30+
makedirs(pardir+"\\"+name)
31+
32+
33+
# Deletes a directory
34+
def delete_directory(name):
35+
removedirs(name)
36+
37+
38+
# Rename a directory
39+
def rename_directory(direct, name):
40+
rename(direct, name)
41+
42+
43+
# Sets the working directory
44+
def set_working_directory():
45+
chdir(pardir)
46+
47+
48+
# Backup the folder tree
49+
def backup_files(name_dir, folder):
50+
copytree(pardir, name_dir + ':\\' + folder)
51+
52+
53+
# Move folder to specific location
54+
# Overwrites the file if it already exists
55+
def move_folder(filename, name_dir, folder):
56+
if not exists(name_dir+":\\"+folder):
57+
makedirs(name_dir+':\\'+folder)
58+
move(filename, name_dir+":\\"+folder+'\\')
59+
60+
61+
"""
62+
For test purpose:
63+
1. create_directory("test")
64+
2. rename_directory("test","demo")
65+
3. delete_directory("demo")
66+
4. backup_files('D', 'backup_project')
67+
5. move_folder(pardir+'\\'+'test.txt', 'D', 'name')
68+
"""
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""
2+
Code to directly use in file to
3+
create directory in home location
4+
5+
Note:- I Have used python package so if you want
6+
to create in the main directory of your project use
7+
pardir+"\\"+name in functions
8+
9+
All the folder operations are done on home
10+
project directory.
11+
"""
12+
13+
from shutil import copytree
14+
from shutil import move
15+
from os import chdir
16+
from os.path import exists
17+
from os.path import pardir
18+
from os import makedirs
19+
from os import removedirs
20+
from os import rename
21+
22+
23+
# Creates a directory
24+
def create_directory(name):
25+
if exists(pardir+"\\"+name):
26+
print('Folder already exists... Cannot Overwrite this')
27+
else:
28+
makedirs(pardir+"\\"+name)
29+
30+
31+
# Deletes a directory
32+
def delete_directory(name):
33+
removedirs(name)
34+
35+
36+
# Rename a directory
37+
def rename_directory(direct, name):
38+
rename(direct, name)
39+
40+
41+
# Sets the working directory
42+
def set_working_directory():
43+
chdir(pardir)
44+
45+
46+
# Backup the folder tree
47+
def backup_files(name_dir, folder):
48+
copytree(pardir, name_dir + ':\\' + folder)
49+
50+
51+
# Move folder to specific location
52+
# Overwrites the file if it already exists
53+
def move_folder(filename, name_dir, folder):
54+
if not exists(name_dir+":\\"+folder):
55+
makedirs(name_dir+':\\'+folder)
56+
move(filename, name_dir+":\\"+folder+'\\')
57+
58+
59+
"""
60+
For test purpose:
61+
1. create_directory("test")
62+
2. rename_directory("test","demo")
63+
3. delete_directory("demo")
64+
4. backup_files('D', 'backup_project')
65+
5. move_folder(pardir+'\\'+'test.txt', 'D', 'name')
66+
"""
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#!/usr/bin/python3
2+
3+
from os import chdir
4+
import requests
5+
from bs4 import BeautifulSoup
6+
from urllib.request import urlopen, Request
7+
from urllib.parse import urlencode
8+
from os import walk
9+
import json
10+
from os.path import curdir
11+
from urllib.request import urlretrieve
12+
from os.path import pardir
13+
from create_dir import create_directory
14+
15+
GOOGLE_IMAGE = 'https://www.google.com/search?site=&tbm=isch&source=hp&biw=1873&bih=990&'
16+
WALLPAPERS_KRAFT = 'https://wallpaperscraft.com/search/keywords?'
17+
usr_agent = {
18+
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
19+
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
20+
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
21+
'Accept-Encoding': 'none',
22+
'Accept-Language': 'en-US,en;q=0.8',
23+
'Connection': 'keep-alive'
24+
}
25+
26+
27+
def image_grabber(ch):
28+
29+
# Download images from google images
30+
if ch == 1:
31+
print('Enter data to download Images: ')
32+
data = input()
33+
search_query = {'q': data}
34+
search = urlencode(search_query)
35+
print(search)
36+
g = GOOGLE_IMAGE + search
37+
request = Request(g, headers=usr_agent)
38+
r = urlopen(request).read()
39+
sew = BeautifulSoup(r, 'html.parser')
40+
images = []
41+
# print(sew.prettify())
42+
results = sew.findAll("div",{"class":"rg_meta"})
43+
for re in results:
44+
link, Type = json.loads(re.text)["ou"] , json.loads(re.text)["ity"]
45+
images.append(link)
46+
counter = 0
47+
for re in images:
48+
rs = requests.get(re)
49+
with open('img' + str(counter) + '.jpg', 'wb') as file:
50+
file.write(rs.content)
51+
# urlretrieve(re, 'img' + str(count) + '.jpg')
52+
counter += 1
53+
return True
54+
55+
elif ch == 2:
56+
cont = set() # Stores the links of images
57+
temp = set() # Refines the links to download images
58+
59+
print('Enter data to download wallpapers: ')
60+
data = input()
61+
search_query = {'q': data}
62+
search = urlencode(search_query)
63+
print(search)
64+
g = WALLPAPERS_KRAFT + search
65+
request = Request(g, headers=usr_agent)
66+
r = urlopen(request).read()
67+
sew = BeautifulSoup(r, 'html.parser')
68+
count = 0
69+
for links in sew.find_all('a'):
70+
if 'wallpaperscraft.com/download' in links.get('href'):
71+
cont.add(links.get('href'))
72+
for re in cont:
73+
# print all valid links
74+
# print('https://wallpaperscraft.com/image/' + re[31:-10] + '_' + re[-9:] + '.jpg')
75+
temp.add('https://wallpaperscraft.com/image/' + re[31:-10] + '_' + re[-9:] + '.jpg')
76+
77+
# Goes to Each link and downloads high resolution images
78+
79+
for re in temp:
80+
rs = requests.get(re)
81+
with open('img' + str(count) + '.jpg', 'wb') as file:
82+
file.write(rs.content)
83+
# urlretrieve(re, 'img' + str(count) + '.jpg')
84+
count += 1
85+
86+
return True
87+
88+
elif ch == 3:
89+
for folders, subfolder, files in walk(curdir):
90+
for folder in subfolder:
91+
print(folder)
92+
return True
93+
94+
elif ch == 4:
95+
print('Enter the directory to be set: ')
96+
data = input()
97+
chdir(data + ':\\')
98+
print('Enter name for the folder: ')
99+
data = input()
100+
create_directory(data)
101+
return True
102+
103+
elif ch == 5:
104+
print(
105+
'''
106+
-------------------------***Thank You For Using***-------------------------
107+
'''
108+
)
109+
return False
110+
111+
112+
run = True
113+
114+
print(
115+
'''
116+
***********[First Creating Folder To Save Your Images}***********
117+
'''
118+
)
119+
120+
create_directory('Images')
121+
DEFAULT_DIRECTORY = pardir + '\\Images'
122+
chdir(DEFAULT_DIRECTORY)
123+
124+
while run:
125+
print('''
126+
-------------------------WELCOME-------------------------
127+
1. Search for image
128+
2. Download Wallpapers 1080p
129+
3. View Images in your directory
130+
4. Set directory
131+
5. Exit
132+
-------------------------*******-------------------------
133+
''')
134+
choice = input()
135+
run = image_grabber(int(choice))

0 commit comments

Comments
 (0)