Skip to content

Commit 6c2b34e

Browse files
committed
Merge branch 'master' of https://github.com/chavarera/python-mini-projects into fetch_imdb_ratings
2 parents 6f1ad08 + 53950a3 commit 6c2b34e

18 files changed

Lines changed: 473 additions & 1 deletion

‎README.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# Mini-Projects-Python
88

9-
[![All Contributors](https://img.shields.io/badge/all_contributors-39-cyan.svg?style=flat-square)](#contributors-)
9+
[![All Contributors](https://img.shields.io/badge/all_contributors-41-blue.svg?style=flat-square)](#contributors-)
1010
![Issues](https://img.shields.io/github/issues/chavarera/python-mini-projects)
1111
![Pull Requests](https://img.shields.io/github/issues-pr/chavarera/python-mini-projects?)
1212
![Forks](https://img.shields.io/github/forks/chavarera/python-mini-projects)
@@ -171,3 +171,7 @@ SR No | Project | Author
171171
86 | [Convert JPEG to PNG](https://github.com/chavarera/python-mini-projects/tree/master/projects/Convert_JPEG_to_PNG)| [AnuragGupta](https://github.com/AnuragGupta806)
172172
87 | [Movie Information Scrapper](https://github.com/chavarera/python-mini-projects/tree/master/projects/Movie%20Information%20Scraper)| [Anandha Krishnan Aji](https://github.com/anandhakrishnanaji)
173173
88 | [Fetch HTTP Status Code](https://github.com/chavarera/python-mini-projects/tree/master/projects/Fetch%20HTTP%20status%20code)| [AkshataJ96](https://github.com/AkshataJ96)
174+
89 | [Check Leap Year](https://github.com/chavarera/python-mini-projects/tree/master/projects/Leap_Year_Checker)| [Hariom Vyas](https://github.com/Hariom1509)
175+
90 | [Scrape Medium Articles](https://github.com/chavarera/python-mini-projects/tree/master/projects/Scraping%20Medium%20Articles)| [Naman Shah](https://github.com/namanshah01)
176+
91 | [HackerNews Scrapper](https://github.com/chavarera/python-mini-projects/tree/master/projects/Scrape_Hacker_News)| [Javokhirbek](https://github.com/leader2one)
177+
92 | [Reduce Image Size](https://github.com/chavarera/python-mini-projects/tree/master/projects/Reduce_image_file_size)| [Vipul Verma](https://github.com/VIPverma01)

‎docs/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,7 @@ SR No | Project | Author
9393
86 | [Convert JPEG to PNG](https://github.com/chavarera/python-mini-projects/tree/master/projects/Convert_JPEG_to_PNG)| [AnuragGupta](https://github.com/AnuragGupta806)
9494
87 | [Movie Information Scrapper](https://github.com/chavarera/python-mini-projects/tree/master/projects/Movie%20Information%20Scraper)| [Anandha Krishnan Aji](https://github.com/anandhakrishnanaji)
9595
88 | [Fetch HTTP Status Code](https://github.com/chavarera/python-mini-projects/tree/master/projects/Fetch%20HTTP%20status%20code)| [AkshataJ96](https://github.com/AkshataJ96)
96+
89 | [Check Leap Year](https://github.com/chavarera/python-mini-projects/tree/master/projects/Leap_Year_Checker)| [Hariom Vyas](https://github.com/Hariom1509)
97+
90 | [Scrape Medium Articles](https://github.com/chavarera/python-mini-projects/tree/master/projects/Scraping%20Medium%20Articles)| [Naman Shah](https://github.com/namanshah01)
98+
91 | [HackerNews Scrapper](https://github.com/chavarera/python-mini-projects/tree/master/projects/Scrape_Hacker_News)| [Javokhirbek](https://github.com/leader2one)
99+
92 | [Reduce Image Size](https://github.com/chavarera/python-mini-projects/tree/master/projects/Reduce_image_file_size)| [Vipul Verma](https://github.com/VIPverma01)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Script Title
2+
<!--Remove the below lines and add yours -->
3+
With the help of this program, you can check whether a year is leap year or not.
4+
### Prerequisites
5+
<!--Remove the below lines and add yours -->
6+
No pre-requisites are required...😀😀
7+
### How to run the script
8+
<!--Remove the below lines and add yours -->
9+
You can run this on any ide or online compiler.
10+
11+
## *Author Name*
12+
<!--Remove the below lines and add yours -->
13+
[Hariom1509](https://github.com/Hariom1509)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
year = int(input("Enter a year:- ")) # Here, you take the input from the user
2+
3+
if(((year % 4 == 0) and (year % 100 != 0)) or (year % 400 == 0)):
4+
"""
5+
if a year is a multiple of four and a multiple of 100 i.e. if it is a multiple of 400 it is not a leap year
6+
"""
7+
print("{0} is a leap year!!".format(year))
8+
"""
9+
printing the output
10+
"""
11+
else:
12+
print("{0} is not a leap year!!".format(year))
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Script Title
2+
#### Script to reduce the size of image file using the openCV library of python.
3+
4+
### Prerequisites
5+
openCV library
6+
7+
`pip install opencv-python`
8+
9+
### How to run the script
10+
- Add the image in jpg format with name as 'input.jpg' in this folder.
11+
- Run reduce_image_size.py script.
12+
- resized output image will be generated in this folder.
13+
14+
## *Author Name*
15+
### *Vipul Verma*
603 KB
Loading
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# import openCV library for image handling
2+
import cv2
3+
4+
# read image to be resized by imread() function of openCV library
5+
img = cv2.imread('input.jpg')
6+
print(img.shape)
7+
8+
# set the ratio of resized image
9+
k = 5
10+
width = int((img.shape[1])/k)
11+
height = int((img.shape[0])/k)
12+
13+
# resize the image by resize() function of openCV library
14+
scaled = cv2.resize(img, (width, height), interpolation=cv2.INTER_AREA)
15+
print(scaled.shape)
16+
17+
# show the resized image using imshow() function of openCV library
18+
cv2.imshow("Output", scaled)
19+
cv2.waitKey(500)
20+
cv2.destroyAllWindows()
21+
22+
# get the resized image output by imwrite() function of openCV library
23+
cv2.imwrite('resized_output_image.jpg', scaled)
46.9 KB
Loading
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Scrape News From HackerNews website
2+
3+
A script that scrapes a number of pages from HackerNews
4+
5+
6+
### How to run the script
7+
In command go to the file directory, and "run python main.py" in commandline
8+
9+
10+
## *Author Name*
11+
Developed by Javokhir
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import requests
2+
import os
3+
from multiprocessing import Pool, cpu_count
4+
from functools import partial
5+
from bs4 import BeautifulSoup, SoupStrainer
6+
# Makes Output Directory if it does not exist
7+
if not os.path.exists(os.path.join(os.getcwd(), 'HackerNews')):
8+
os.makedirs(os.path.join(os.getcwd(), 'HackerNews'))
9+
'''
10+
@params page_no: The page number of HackerNews to fetch.
11+
Adding only page number in order to add multiprocess support in future.
12+
@params verbose: Adds verbose output to screen instead
13+
of running the program silently.
14+
'''
15+
16+
17+
def fetch(page_no, verbose=False):
18+
# Should be unreachable, but just in case
19+
if page_no <= 0:
20+
raise ValueError('Number of Pages must be greater than zero')
21+
page_no = min(page_no, 20)
22+
i = page_no
23+
if verbose:
24+
print('Fetching Page {}...'.format(i))
25+
try:
26+
res = requests.get('https://news.ycombinator.com/?p=' + str(i))
27+
only_td = SoupStrainer('td')
28+
soup = BeautifulSoup(res.content, 'html.parser', parse_only=only_td)
29+
tdtitle = soup.find_all('td', attrs={'class': 'title'})
30+
tdmetrics = soup.find_all('td', attrs={'class': 'subtext'})
31+
with open(os.path.join('HackerNews', 'NewsPage{}.txt'.format(i)), 'w+') as f:
32+
f.write('-' * 80)
33+
f.write('\n')
34+
f.write('Page {}'.format(i))
35+
tdtitle = soup.find_all('td', attrs={'class': 'title'})
36+
tdrank = soup.find_all(
37+
'td',
38+
attrs={
39+
'class': 'title',
40+
'align': 'right'})
41+
tdtitleonly = [t for t in tdtitle if t not in tdrank]
42+
tdmetrics = soup.find_all('td', attrs={'class': 'subtext'})
43+
tdt = tdtitleonly
44+
tdr = tdrank
45+
tdm = tdmetrics
46+
num_iter = min(len(tdr), len(tdt))
47+
for idx in range(num_iter):
48+
f.write('\n' + '-' * 80 + '\n')
49+
rank = tdr[idx].find('span', attrs={'class': 'rank'})
50+
titl = tdt[idx].find('a', attrs={'class': 'storylink'})
51+
url = titl['href'] if titl and titl['href'].startswith(
52+
'https') else 'https://news.ycombinator.com/' + titl['href']
53+
site = tdt[idx].find('span', attrs={'class': 'sitestr'})
54+
score = tdm[idx].find('span', attrs={'class': 'score'})
55+
time = tdm[idx].find('span', attrs={'class': 'age'})
56+
author = tdm[idx].find('a', attrs={'class': 'hnuser'})
57+
f.write(
58+
'\nArticle Number: ' +
59+
rank.text.replace(
60+
'.',
61+
'') if rank else '\nArticle Number: Could not get article number')
62+
f.write(
63+
'\nArticle Title: ' +
64+
titl.text if titl else '\nArticle Title: Could not get article title')
65+
f.write(
66+
'\nSource Website: ' +
67+
site.text if site else '\nSource Website: https://news.ycombinator.com')
68+
f.write(
69+
'\nSource URL: ' +
70+
url if url else '\nSource URL: No URL found for this article')
71+
f.write(
72+
'\nArticle Author: ' +
73+
author.text if author else '\nArticle Author: Could not get article author')
74+
f.write(
75+
'\nArticle Score: ' +
76+
score.text if score else '\nArticle Score: Not Scored')
77+
f.write(
78+
'\nPosted: ' +
79+
time.text if time else '\nPosted: Could not find when the article was posted')
80+
f.write('\n' + '-' * 80 + '\n')
81+
except (requests.ConnectionError, requests.packages.urllib3.exceptions.ConnectionError) as e:
82+
print('Connection Failed for page {}'.format(i))
83+
except requests.RequestException as e:
84+
print("Some ambiguous Request Exception occurred. The exception is " + str(e))
85+
86+
87+
while(True):
88+
try:
89+
pages = int(
90+
input('Enter number of pages that you want the HackerNews for (max 20): '))
91+
v = input('Want verbose output y/[n] ?')
92+
verbose = v.lower().startswith('y')
93+
if pages > 20:
94+
print('A maximum of only 20 pages can be fetched')
95+
pages = min(pages, 20)
96+
for page_no in range(1, pages + 1):
97+
fetch(page_no, verbose)
98+
break
99+
except ValueError as e:
100+
print('\nInvalid input, probably not a positive integer\n')
101+
continue

0 commit comments

Comments
 (0)