mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-23 20:11:07 +00:00
Added Python made News Generator HackerNews (#174)
This commit is contained in:
parent
3f90a01a5e
commit
b9f4162f13
|
@ -58,6 +58,7 @@ So far, the following projects have been integrated to this repo:
|
|||
|[SMS your location](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/SmsYourLocation)|[prince]()|
|
||||
|[Squid installer for Ubuntu](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Squid-Proxy-Installer-for-Ubuntu16)|[Berkay Demir]()|
|
||||
|[Subtitle downloader](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Subtitle-downloader)|[Kaushlendra Pratap](https://github.com/kaushl1998)|
|
||||
|[Top_News](Top_News)|[Attupatil](https://github.com/Attupatil)|
|
||||
|[Take Screenshot](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Take_screenshot)|[Moad Mohammed Elhebri](https://github.com/moadmmh)|
|
||||
|[To Do Bot](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/To-Do-Bot) | [Darshan Patel](https://github.com/DarshanPatel11)|
|
||||
|[Upload Files to S3](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Upload_files_to_s3)|[Jayram Nai](https://github.com/jramnai)|
|
||||
|
|
21
Top_News/Readme.md
Normal file
21
Top_News/Readme.md
Normal file
|
@ -0,0 +1,21 @@
|
|||
### Cool IT news
|
||||
This python made script shows top voted news `basic version votes>99` from hackernews.
|
||||
|
||||
### Installation
|
||||
First of all use
|
||||
|
||||
```
|
||||
pip install requirements.txt
|
||||
```
|
||||
|
||||
### Run
|
||||
|
||||
```
|
||||
python coolnews.py
|
||||
```
|
||||
|
||||
##
|
||||
If you want news of more then desired number of votes you can edit
|
||||
```
|
||||
Line 29. if points > 99:
|
||||
```
|
34
Top_News/coolnews.py
Normal file
34
Top_News/coolnews.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
import pprint
|
||||
|
||||
res = requests.get('https://news.ycombinator.com/news')
|
||||
res2 = requests.get('https://news.ycombinator.com/news?p=2')
|
||||
soup = BeautifulSoup(res.text, 'html.parser')
|
||||
soup2 = BeautifulSoup(res2.text, 'html.parser')
|
||||
|
||||
links = soup.select('.storylink')
|
||||
subtext = soup.select('.subtext')
|
||||
links2 = soup2.select('.storylink')
|
||||
subtext2 = soup2.select('.subtext')
|
||||
|
||||
mega_links = links + links2
|
||||
mega_subtext = subtext + subtext2
|
||||
|
||||
def sort_stories_by_votes(hnlist):
|
||||
return sorted(hnlist, key= lambda k:k['votes'],reverse=True)
|
||||
|
||||
def create_custom_hn(links,subtext):
|
||||
hn=[]
|
||||
for idx, item in enumerate(links):
|
||||
title =item.getText()
|
||||
href = item.get('href',None)
|
||||
vote = subtext[idx].select('.score')
|
||||
if len(vote):
|
||||
points = int(vote[0].getText().replace(' points',''))
|
||||
if points > 99:
|
||||
hn.append({'title':title,'link':href,'votes':points})
|
||||
return sort_stories_by_votes(hn)
|
||||
|
||||
pprint.pprint(create_custom_hn(mega_links, mega_subtext))
|
||||
|
2
Top_News/requirements.txt
Normal file
2
Top_News/requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
requests==2.24.0
|
||||
bs4==0.0.1
|
Loading…
Reference in New Issue
Block a user