Skip to content

yarink3/subreddit-presenter

Repository files navigation

Subbredit Presenter

The Subbredit Presenter is a full stack application to present Reddit.com subreddits in a useful way.

Table of contents

General info

This project uses Python flask , JavaScript and HTML in order to display information about the articles of the subbredit asked by the user.

Screenshots

main web page

Technologies

  • Server - Python (3.7) flask
  • Client - JavaScript, HTML

Link to the website (UI version)

Setup

  • install python 3 (or above)
  • install pip (sudo apt-get install python3-pip)
  • install flask (pip3 install Flask)

How to run

How it works

  • A flask application created from 'app.py' , renders the template 'index.html' and creates a server.
  • The user fill the form - ask for a specific subreddit and the number of articles (up to 100), sent by post request to the server with the deatails.
  • The server converts the json from the reddit website, send it back to the client and the deatails being displayed to the user.

Code Examples

   def get_articles(subreddit, num_of_articles):
    
    id = 0
    message_lst = []
    params = (('limit', str(num_of_articles)),)
    while (True):
        try:

            response = requests.get(f'https://www.reddit.com/r/{subreddit}/.json', headers=headers, params=params)
            json_respone = response.json()
            datas_children = json_respone['data']['children']
            for item in datas_children:
                article = [{
                    "id": id,
                    "Title": item['data']['title'],
                    "Author": item['data']['author'],
                    "Url": item['data']['url'],
                    "Posted at": get_date(int(item['data']['created_utc'])),
                    "Score": item['data']['score'],

                }]
                article = article[0]

                message_lst.append(f"Article number {str(article['id'] + 1)}:\n ")
                message_lst.append(f"Title: {article['Title']}")
                message_lst.append(f"by  {article['Author']}/")
                message_lst.append(f"Article's link: {article['Url']}\n")
                message_lst.append(f"Posted on {article['Posted at']}\n")
                message_lst.append(f"Has a score of {article['Score']} \n")
                message_lst.append("\n")
                id = id + 1


        except:
            return ["wrong subreddit name, Please try again"]

        return message_lst

Features

  • Rest API - to communicate between the server and the client.

Status

Project is: finished

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published