Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Commit 1718272

Browse files
Merge pull request #1 from ankitdobhal/master
To get Sync with original project
2 parents 405f564 + d56a8c1 commit 1718272

File tree

5 files changed

+178
-13
lines changed

5 files changed

+178
-13
lines changed

Basic-Scripts/balanced_paranthesis.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
openBracketList = ["[", "{", "("]
2+
closeBracketList = ["]", "}", ")"]
3+
4+
5+
def check_parentheses(data: str) -> str:
6+
"""
7+
check_parentheses() : Will take a string as an arguement and each time when an open parentheses is encountered
8+
will push it in the stack, and when closed parenthesis is encountered,
9+
will match it with the top of stack and pop it.
10+
11+
Parameters:
12+
data (str): takes a string.
13+
14+
Returns:
15+
str: Returns a string value whether string passed is balanced or Unbalanced.
16+
"""
17+
stack = []
18+
for index in data:
19+
if index in openBracketList:
20+
stack.append(index)
21+
elif index in closeBracketList:
22+
position = closeBracketList.index(index)
23+
if (len(stack) > 0) and (
24+
openBracketList[position] == stack[len(stack) - 1]
25+
):
26+
stack.pop()
27+
else:
28+
return "Unbalanced"
29+
if len(stack) == 0:
30+
return "Balanced"
31+
else:
32+
return "Unbalanced"
33+
34+
35+
if __name__ == "__main__":
36+
37+
data = input("Enter the string to check:\t")
38+
result = check_parentheses(data)
39+
print(result)
40+

Contribution.md

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,29 @@
22
If this is your first time to open source contribution in python So that I have created this repo for all the you to start contributing.
33

44
# How to contribute!
5-
## Steps:
6-
* fork the [repository](https://github.com/ankitdobhal/Python-Scripts)
7-
* Clone the fork [repo](https://github.com/ankitdobhal/Python-Scripts)
8-
(git clone https://github.com/ankitdobhal/Python-Scripts)
9-
* Create new branch
10-
(git checkout -b <Your-Branch-Name>)
11-
* Add files in scripts folder
12-
(git add <your-contribution>)
13-
* Add a commit message !
14-
(git commit -a -m "<Added your message>")
15-
* Push changes
16-
(git push origin)
17-
* Create pull requests
5+
6+
## Steps:
7+
- First commment on the issue in which you want to work upon.
8+
- Issue-1 : https://github.com/ankitdobhal/Awesome-Python-Scripts/issues/91
9+
- Issue-2 : https://github.com/ankitdobhal/Awesome-Python-Scripts/issues/92
10+
- Issue-3 : https://github.com/ankitdobhal/Awesome-Python-Scripts/issues/93
11+
- Issue-4 : https://github.com/ankitdobhal/Awesome-Python-Scripts/issues/94
12+
13+
- Fork the [repository](https://github.com/ankitdobhal/Awesome-Python-Scripts)
14+
15+
- Clone the fork [repo](https://github.com/ankitdobhal/Awesome-Python-Scripts)
16+
- git clone https://github.com/<Your_Username>/Awesome-Python-Scripts
17+
- Create new branch
18+
- git checkout -b <Your-Branch-Name>
19+
20+
- Add Scripts related to your respective issues.
21+
- git add <your-contribution>
22+
23+
- Add a commit message !
24+
- git commit -a -m "<Added your message>"
25+
26+
- Push changes
27+
- git push -u origin <name_of_your_branch>
28+
29+
- Create pull requests
30+
- [Try to Mention the related issue for your PR]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import os
2+
from pathlib import Path as pt
3+
4+
DIRECTORIES = {
5+
"HTML": [".html5", ".html", ".htm", ".xhtml"],
6+
"IMAGES": [".jpeg", ".jpg", ".tiff", ".gif", ".bmp", ".png", ".bpg", "svg",
7+
".heif", ".psd"],
8+
"VIDEOS": [".avi", ".flv", ".wmv", ".mov", ".mp4", ".webm", ".vob", ".mng",
9+
".qt", ".mpg", ".mpeg", ".3gp"],
10+
"DOCUMENTS": [".oxps", ".epub", ".pages", ".docx", ".doc", ".fdf", ".ods",
11+
".odt", ".pwi", ".xsn", ".xps", ".dotx", ".docm", ".dox",
12+
".rvg", ".rtf", ".rtfd", ".wpd", ".xls", ".xlsx", ".ppt",
13+
"pptx"],
14+
"ARCHIVES": [".a", ".ar", ".cpio", ".iso", ".tar", ".gz", ".rz", ".7z",
15+
".dmg", ".rar", ".xar", ".zip"],
16+
"AUDIO": [".aac", ".aa", ".aac", ".dvf", ".m4a", ".m4b", ".m4p", ".mp3",
17+
".msv", "ogg", "oga", ".raw", ".vox", ".wav", ".wma"],
18+
"PLAINTEXT": [".txt", ".in", ".out"],
19+
"PDF": [".pdf"],
20+
"PYTHON": [".py"],
21+
"C": [".c"],
22+
"CPP": [".cpp"],
23+
"JAVA": [".java"],
24+
"XML": [".xml"],
25+
"EXE": [".exe"],
26+
"SHELL": [".sh"]
27+
28+
}
29+
30+
FILE_FORMATS = {file_format: directory
31+
for directory, file_formats in DIRECTORIES.items()
32+
for file_format in file_formats}
33+
34+
def org_junk():
35+
for entry in os.scandir():
36+
if entry.is_dir():
37+
continue
38+
file_path = pt(entry)
39+
file_format = file_path.suffix.lower()
40+
if file_format in FILE_FORMATS:
41+
directory_path = pt(FILE_FORMATS[file_format])
42+
directory_path.mkdir(exist_ok=True)
43+
file_path.rename(directory_path.joinpath(file_path))
44+
45+
for dir in os.scandir():
46+
try:
47+
os.rmdir(dir)
48+
except:
49+
pass
50+
51+
if __name__ == "__main__":
52+
org_junk()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Scraping Hacker news Website
2+
3+
Scraping the first 2 pages of Hacker news website wherein user can read Tech news(as a articles) which has upvotes more than 100 with help of Requests and
4+
Beautiful Soup Modules. User can just click on story link to see the article.
5+
6+
Link for Hacker news Website - https://news.ycombinator.com/
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
'''
2+
Scraping the first 2 pages of Hacker news website which gives lot of Tech news(as a articles)
3+
which has upvotes more than 100.User can just click on story link to see the article.
4+
'''
5+
6+
'''
7+
Program uses requests module to get web data from URL and BeautifulSoup module to parse the web data
8+
as HTML using html parser.
9+
Install requests and BeautifulSoup module before executing!
10+
'''
11+
12+
import requests
13+
from bs4 import BeautifulSoup
14+
import pprint # prints the Final output in pretty manner which is inbuilt module in Python
15+
16+
17+
response1 = requests.get("https://news.ycombinator.com/news") #Storing response of first page of website
18+
response2 = requests.get("https://news.ycombinator.com/news?p=2") # Storing response of Second page of website
19+
20+
response1_html_parser = BeautifulSoup(response1.text,'html.parser') #parsing the received web data by html parser
21+
response2_html_parser = BeautifulSoup(response2.text,'html.parser')
22+
23+
linksInPage1 = response1_html_parser.select('.storylink') #All links of tech news are included in class "Storylink"
24+
linksInPage2 = response2_html_parser.select('.storylink')
25+
26+
votesInPage1 = response1_html_parser.select('.subtext') #All votes are stored inside subclass "score" of class "subtext"
27+
votesInPage2 = response2_html_parser.select('.subtext')
28+
29+
30+
mega_link = linksInPage1 + linksInPage2 # Combining links of both pages
31+
#print(mega_link)
32+
mega_votes = votesInPage1 + votesInPage2
33+
34+
def sorted_stories_list(hackerNewsList):
35+
"""Sorting the list in decreasing order
36+
with respect to votes"""
37+
return sorted(hackerNewsList,key=lambda x:x['votes'],reverse=True)
38+
39+
def create_custom_hackernews(mega_link,mega_votes):
40+
hackerNews =[]
41+
for index,item in enumerate(mega_link):
42+
title = mega_link[index].getText() #To get title of the story(news)
43+
href = mega_link[index].get('href',None) # To get link of stroy(news).If no link is present, default is None
44+
vote = mega_votes[index].select('.score') # points are stored inside class "score" of class subtext,if points/votes not available, then class score wont be present.
45+
if len(vote): #To check if class "score" exists or not
46+
points = int(vote[0].getText().replace(' points', ''))
47+
if points > 100: # To get votes/points more than 100
48+
hackerNews.append({'title': title, 'link': href,'votes': points})
49+
50+
return sorted_stories_list(hackerNews)
51+
52+
if __name__ == '__main__':
53+
# Prints story link, story title and its votes in a pretty manner
54+
pprint.pprint(create_custom_hackernews(mega_link,mega_votes))

0 commit comments

Comments
 (0)