Skip to content

Commit 06617a5

Browse files
authored
Merge branch 'larymak:main' into sudoku-solver
2 parents 7027ea7 + e747969 commit 06617a5

17 files changed

+386
-0
lines changed

AudioBuk/audio.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import PyPDF2
2+
import pyttsx3
3+
from tkinter.filedialog import *
4+
5+
book = askopenfilename()
6+
pdfReader = PyPDF2.PdfFileReader(book)
7+
8+
pages = pdfReader.numPages
9+
10+
for num in range(0, pages):
11+
page = pdfReader.getPage(num)
12+
text = page.extractText()
13+
speak = pyttsx3.init()
14+
speak.say(text)
15+
speak.runAndWait()

Geocoding Google API/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## HOW TO USE:
2+
1. Simply just grab an api key from the google maps api/geocode.
3+
2. Create an excel workbook with a name of your choosing.
4+
3. Create a sheet name in this excel workbook with a name of your choosing.
5+
4a. Create a column labeled address where your addresses will be listed
6+
4b. If you want to label your column something else, you can do so, but make sure to change it in the geo.py file
7+
5. The program will then grab each address and convert it to fit the url format and then fetch the corresponding latitude
8+
& longitutde to be returned
9+
6. It will be then outputed to a new excel file called output and saved.
10+
11+
'''
12+
'''
13+
if there is an error in retrieving the lat or long, the program
14+
will instead put a 0,0. this is because the program doesn't account for errors on the request
15+
of which it responds with a 200 success, but results in an index out of bounds error
16+
because the return specifies the api key is wrong yet it is right.
17+
for the few entries this problem occurs it can be done manually or programmed further to account for
18+

Geocoding Google API/geo.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import pandas as pd
2+
import requests
3+
import openpyxl
4+
from requests.models import HTTPError
5+
import xlsxwriter
6+
'''
7+
HOW TO USE:
8+
1. Simply just grab an api key from the google maps api/geocode.
9+
2. Create an excel workbook with a name of your choosing.
10+
3. Create a sheet name in this excel workbook with a name of your choosing.
11+
4a. Create a column labeled address where your addresses will be listed
12+
4b. If you want to label your column something else, you can do so, but make sure to change it in the geo.py file
13+
5. The program will then grab each address and convert it to fit the url format and then fetch the corresponding latitude
14+
& longitutde to be returned
15+
6. It will be then outputed to a new excel file called output and saved.
16+
17+
'''
18+
'''
19+
if there is an error in retrieving the lat or long, the program
20+
will instead put a 0,0. this is because the program doesn't account for errors on the request
21+
of which it responds with a 200 success, but results in an index out of bounds error
22+
because the return specifies the api key is wrong yet it is right.
23+
for the few entries this problem occurs it can be done manually or programmed further to account for
24+
25+
26+
'''
27+
my_new_data = []
28+
29+
workbook = xlsxwriter.Workbook('output.xlsx')
30+
worksheet = workbook.add_worksheet()
31+
32+
# editable
33+
COLUMN_IDX_START = 10 # -> corresponds to the latitude column
34+
COLUMN_IDX_START_2 = 11 # -> corresponds to the longitude column
35+
WORKBOOK_NAME = 'YOURWORKBOOKNAMEHERE.xlsx'
36+
SHEET_NAME = 'YOURSHEETNAMEHERE'
37+
COLUMN_NAME = 'address'
38+
MAPS_URL = 'https://maps.googleapis.com/maps/api/geocode/json?address='
39+
GOOGLE_API_KEY = 'YOURAPI_KEY HERE'
40+
API_KEY = '&key=' + GOOGLE_API_KEY
41+
42+
43+
def getGeoCodeFromAddress():
44+
wb = openpyxl.load_workbook(WORKBOOK_NAME)
45+
ws = wb[SHEET_NAME]
46+
excel_data_df = pd.read_excel(WORKBOOK_NAME, sheet_name=SHEET_NAME)
47+
list_data = excel_data_df[COLUMN_NAME].tolist()
48+
for address in list_data:
49+
sanitized_add = address.replace(" ", "+")
50+
my_new_data.append(sanitized_add)
51+
for row_num, data in enumerate(my_new_data, start=1):
52+
try:
53+
lat, long = getLatAndLong(data)
54+
except:
55+
lat, long = 0, 0
56+
worksheet.write(row_num, COLUMN_IDX_START, lat)
57+
worksheet.write(row_num, COLUMN_IDX_START_2, long)
58+
workbook.close()
59+
60+
61+
def getLatAndLong(url):
62+
url = MAPS_URL + url + API_KEY
63+
try:
64+
response = requests.get(url)
65+
except HTTPError as http_err:
66+
print(f'HTTP error occurred: {http_err}') # Python 3.6
67+
except Exception as err:
68+
print(f'Other error occurred: {err}') # Python 3.6
69+
else:
70+
print('Success!')
71+
72+
json_response = response.json()
73+
data = json_response['results'][0]['geometry']['location']
74+
latitude = data['lat']
75+
longitutde = data['lng']
76+
# print(str(latitude) + 'lat')
77+
# print(str(longitutde) + 'long')
78+
return latitude, longitutde
79+
80+
81+
getGeoCodeFromAddress()

Geocoding Google API/requirements.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
certifi==2021.5.30
2+
charset-normalizer==2.0.4
3+
et-xmlfile==1.1.0
4+
idna==3.2
5+
numpy==1.21.1
6+
openpyxl==3.0.7
7+
pandas==1.3.1
8+
python-dateutil==2.8.2
9+
pytz==2021.1
10+
requests==2.26.0
11+
six==1.16.0
12+
urllib3==1.26.6
13+
XlsxWriter==1.4.5

News_Article_Scraping/Article.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
###############################################################################
2+
"""
3+
@Newspaper3k usage
4+
@Usage of functions in newspaper:
5+
@Some Useful functions
6+
================================
7+
To create an instance of article
8+
9+
article_name = Article(url, language="language code according to newspaper")
10+
11+
To download an article
12+
article_name.download()
13+
To parse an article
14+
15+
article_name.parse()
16+
To apply nlp(natural language procesing) on article
17+
18+
article_name.nlp()
19+
To extract article’s text
20+
21+
article_name.text
22+
To extract article’s title
23+
24+
article_name.title
25+
To extract article’s summary
26+
27+
article_name.summary
28+
To extract article’s keywords
29+
30+
article_name.keywords
31+
"""
32+
####################################################################################
33+
34+
#Sample Usage Program
35+
from newspaper import Article
36+
37+
#A new article from TOI
38+
url = "http:// timesofindia.indiatimes.com/world/china/chinese-expert-warns-of-troops-entering-kashmir/articleshow/59516912.cms"
39+
40+
#For different language newspaper refer above table
41+
toi_article = Article(url, language="en") # en for English
42+
43+
#To download the article
44+
toi_article.download()
45+
46+
#To parse the article
47+
toi_article.parse()
48+
49+
#To perform natural language processing ie..nlp
50+
toi_article.nlp()
51+
52+
#To extract title
53+
print("Article's Title:")
54+
print(toi_article.title)
55+
print("n")
56+
57+
#To extract text
58+
print("Article's Text:")
59+
print(toi_article.text)
60+
print("n")
61+
62+
#To extract summary
63+
print("Article's Summary:")
64+
print(toi_article.summary)
65+
print("n")
66+
67+
#To extract keywords
68+
print("Article's Keywords:")
69+
print(toi_article.keywords)
70+
71+
72+
#####################################################################################################################################################################################
73+
"""
74+
Output:
75+
=======
76+
Article's Title:
77+
India China News: Chinese expert warns of troops entering Kashmir
78+
79+
80+
Article's Text:
81+
BEIJING: A Chinese expert has argued that his country's troops would be entitled to enter the Indian side of Kashmir by extending the logic that has permitted Indian troops to enter an area which is disputed by China and Bhutan This is one of the several arguments made by the scholar in an attempt to blame India for. India has responded to efforts by China to build a road in the Doklam area, which falls next to the trijunction connecting Sikkim with Tibet and Bhutan and"Even if India were requested to defend Bhutan's territory, this could only be limited to its established territory, not the disputed area, " Long Xingchun, director of the Center for Indian Studies at China West Normal University said in an article. "Otherwise, under India's logic, if the Pakistani government requests, a third country's army can enter the area disputed by India and Pakistan, including India-controlled Kashmir".China is not just interfering, it is building roads and other infrastructure projects right inside Pakistan-Occupied Kashmir (PoK), which is claimed by both India and Pakistan. This is one of the facts that the article did not mention.The scholar, through his article in the Beijing-based Global Times, suggested that Beijing can internationalize the Doklam controversy without worrying about western countries supporting India because the West has a lot of business to do with China."China can show the region and the international community or even the UN Security Council its evidence to illustrate China's position, " Long said. At the same time, he complained that "Western governments and media kept silent, ignoring India's hegemony over the small countries of South Asia" when India imposed a blockade on the flow of goods to Nepal in 2015.Recent actions by US president Donald Trump, which include selling arms to Taiwan and pressuring China on the North Korean issue, shows that the West is not necessarily cowered down by China's business capabilities.He reiterated the government's stated line that Doklam belongs to China, and that Indian troops had entered the area under the guise of helping Bhutan protect its territory."For a long time, India has been talking about international equality and non-interference in the internal affairs of others, but it has pursued hegemonic diplomacy in South Asia, seriously violating the UN Charter and undermining the basic norms of international relations, " he said.Interestingly, Chinese scholars are worrying about India interfering in Bhutan's "sovereignty and national interests" even though it is Chinese troops who have entered the Doklam area claimed by it."Indians have migrated in large numbers to Nepal and Bhutan, interfering with Nepal's internal affairs. The first challenge for Nepal and Bhutan is to avoid becoming a state of India, like Sikkim, " he said.
82+
83+
84+
Article's Summary:
85+
sending its troops to the disputed Doklam area +puts Indian territory at risk +BEIJING: A Chinese expert has argued that his country's troops would be entitled to enter the Indian side of Kashmir by extending the logic that has permitted Indian troops to enter an area which is disputed by China and Bhutan This is one of the several arguments made by the scholar in an attempt to blame India for.
86+
"Otherwise, under India's logic, if the Pakistani government requests, a third country's army can enter the area disputed by India and Pakistan, including India-controlled Kashmir".China is not just interfering, it is building roads and other infrastructure projects right inside Pakistan-Occupied Kashmir (PoK), which is claimed by both India and Pakistan.
87+
"China can show the region and the international community or even the UN Security Council its evidence to illustrate China's position, " Long said.
88+
"Indians have migrated in large numbers to Nepal and Bhutan, interfering with Nepal's internal affairs.
89+
The first challenge for Nepal and Bhutan is to avoid becoming a state of India, like Sikkim, " he said.
90+
"""
91+
####################################################################################################################################################################################
23.4 KB
Binary file not shown.

News_Article_Scraping/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Article Scraping (Python)
2+
![image](https://user-images.githubusercontent.com/67740644/129327650-24a85343-0371-4e8e-aa42-f290c4a6eb9c.png)
3+
## Description :
4+
Newspaper is a Python module used for extracting and parsing newspaper articles.</br>
5+
Newspaper use advance algorithms with web scrapping to extract all the useful text from a website.</br>
6+
It works amazingly well on online newspapers websites. Since it use web scrapping too many request,</br>
7+
to a newspaper website may lead to blocking, so use it accordingly.
8+
9+
## Installation :
10+
$ pip install newspaper3k (Right Command)
11+
## Note :
12+
$ pip install newspaper (Wrong Command)
13+
14+
## Languages Supported :
15+
Newspaper supports following languages:
16+
17+
input&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;full name</br>
18+
</br>
19+
ar&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Arabic</br>
20+
da&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Danish</br>
21+
de&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;German</br>
22+
el&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Greek</br>
23+
en&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;English</br>
24+
it&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Italian</br>
25+
zh&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Chinese</br>
26+
....etc.
27+
## Link :
28+
You Can Read The original Documentation Here. [NewsPaper3k Documentation](https://newspaper.readthedocs.io/en/latest/)

Number Guessing Game/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Number Guessing Game
2+
3+
This is a game that allows you guess a number between the range of 1- 10 in just 7 trials.
4+
5+
# Prerequisites
6+
7+
It requires no prerequisites, you only need to run the script. If you don't have Python installed, you can visit [here](https://www.python.org/downloads/) to download Python
8+
9+
# How to run the script
10+
11+
Running the script is pretty easy, open a terminal in the folder where your script is located and run the following command :
12+
13+
`python numberGuessingGame.py`
14+
15+
# Sample use of the script
16+
17+
![alt text](https://github.com/Mannuel25/Python-project-Scripts/blob/main/Number%20Guessing%20Game/script_screenshot.png)
18+
19+
20+
# Author's name
21+
22+
[Emmanuel Tanimowo](https://github.com/Mannuel25)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import random
2+
# random module is a built-in module to generate pseudo-random variables
3+
4+
def display_gameplay():
5+
"""
6+
Displays the gameplay
7+
: return: None
8+
"""
9+
print('\nWelcome to Number Guessing Game!')
10+
print('In this game you\'ve just 7 trials to guess a number between the range of 1-10')
11+
print('Note: enter \'exit\' to end game')
12+
13+
def startGame():
14+
"""
15+
Gets user response to start or end the game
16+
: return: str
17+
"""
18+
# call the function to display gameplay
19+
displayGameplay = display_gameplay()
20+
# make a list of the possible inputs
21+
# to start or end the game
22+
POSSIBLE_RESPONSES = ['Y','YES','N','NO','EXIT']
23+
# get user's response
24+
user_response = input('\nStart game? (yes/no): ').strip().upper()
25+
while user_response not in POSSIBLE_RESPONSES:
26+
print('\nInvalid Input!')
27+
user_response = input('\nStart game? (yes/no): ').strip().upper()
28+
else: return user_response
29+
30+
def game():
31+
"""
32+
Controls the game
33+
: return: None
34+
"""
35+
# call the function to get user's response
36+
play_game = startGame()
37+
# assign the number of trials the user has to a variable
38+
number_of_trials = 7
39+
while play_game == 'YES' or play_game == 'Y':
40+
# make a list that contains all the
41+
# numbers a user can guess
42+
ACCEPTED_NUMBER_PICKS = [str(i) for i in range(1,11)]
43+
# get user's number
44+
user_input = input('\nGuess a number between the range of 1-10: ').strip().upper()
45+
while user_input not in ACCEPTED_NUMBER_PICKS and user_input != 'EXIT' :
46+
print('Invalid Input!')
47+
user_input = input('\nGuess a valid number between the range of 1-10: ').strip().upper()
48+
if user_input == 'EXIT':
49+
print('Bye Player!')
50+
break
51+
else:
52+
# generate a random number in the range 1-10
53+
# and assign it to a variable
54+
computer_number = random.randint(1,10)
55+
user_input = int(user_input)
56+
if user_input < computer_number:
57+
number_of_trials -= 1
58+
print(f'Oops, {user_input} is too low')
59+
if number_of_trials != 0:
60+
print(f'You\'ve {number_of_trials} trial(s) left')
61+
play_game = input('\nGuess again? (yes/no): ').strip().upper()
62+
else:
63+
print(F'\nGame over!, you\'ve 0 trial left..try harder next time 😉')
64+
break
65+
elif user_input > computer_number:
66+
number_of_trials -= 1
67+
print(f'Oops, {user_input} is too high')
68+
if number_of_trials != 0:
69+
print(f'You\'ve {number_of_trials} trial(s) left')
70+
play_game = input('\nGuess again? (yes/no): ').strip().upper()
71+
else:
72+
print(F'\nGame over!, you\'ve 0 trial left..try harder next time 😉')
73+
break
74+
elif user_input == computer_number:
75+
number_of_trials -= 1
76+
print(f'Congratulations!!..you guessed right, after {7 - number_of_trials} trial(s)')
77+
play_game = input('\nDo you wish to play again? (yes/no): ').strip().upper()
78+
# if the user wishes to play again, assign
79+
# the number of trials the user has to a variable
80+
number_of_trials = 7
81+
82+
game()
69.2 KB
Loading

PDF merge/Merged_result.pdf

1.1 MB
Binary file not shown.

PDF merge/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
### Merging Multiple PDFs using Python
2+
3+
You Need to open your favourite Editor , create folder name 'PDFmerge' inside create file 'mergePDF.py' copy and paste code from mergePDF.py file this repo.
4+
5+
Open Terminal type
6+
7+
```py
8+
pip install PyPDF2
9+
10+
```
11+
12+
You need to keep PDF files that you want to merge in Python’s working directory.Of course, you can change the directory using Python code. For simplicity of code, I am placing the PDF files on the working directory.
13+
14+
15+
```py
16+
python3 mergePDF.py
17+
18+
```
19+
20+
21+
After Runnig this Code you will get output as the Merged pdf file.

PDF merge/mergePDF.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from PyPDF2 import PdfFileMerger
2+
3+
# array of PDFs which need to merge
4+
pdfs = ['repo.pdf', 'python.pdf']
5+
6+
merger = PdfFileMerger(strict=False)
7+
8+
for pdf in pdfs:
9+
merger.append(pdf)
10+
11+
merger.write("Merged_result.pdf")
12+
print('PDF Merged Wohh !!')
13+
merger.close()

PDF merge/python.pdf

667 KB
Binary file not shown.

PDF merge/repo.pdf

449 KB
Binary file not shown.

0 commit comments

Comments
 (0)