Git Product home page Git Product logo

fresh_script's Introduction

Table of Contents

fresh_script

This program will search for spotify tracks posted in the HipHopHeads subreddit and add them to a playlist of your choice. HipHopHeads is a subreddit dedicated to everything hiphop, including the latest mixtapes, videos, news, and anything else hip hop related from your favorite artists. You can utilize this program as a means to finding the hottest new hiphop music of the current period. This program is a python script does not run like a tradition npm package install; however, it still does require you to clone the repository locally for crediential configuration detailled later.

New Features!

Flask has recently been added to the project. You can read up on how to get it setup here.

Getting Started

Prerequisites

This project uses Python3 and requires either a macOS and/or Linux. Windows is not sufficent for this program. You can download Linux through Windows by downloading wsl.

This app is to be downloaded and run on your machine. To do this, you will need to register your local copy of the app with spotify by creating a Spotify developer account.

Tutorial to setup a Spotify developer account

  1. Connect Spotify Developer to your Spotify account by logging in or creating a free Spotify account here.
  2. Enter your personal dashboard and click the green “Create a Client ID” button to fill out the form to create an app or in our case integrate with our app
  3. Once you fill out the form, return to your dashboard click on the new app you just created and you should see the necessary details for the information needed(listed below).

You will need to register your app and obtain the following information:

  • client id
  • client secret
  • your spotify username
  • playlist id of the playlist you want to add the tracks to
  • the url you want to redirect to for authentication, i.e. http://google.com/
    • this must be added under your app settings > Redirect URIs

You will also need to setup a reddit instance with praw. Here's a useful guide I used to do this.

Setup your Credentials

Download a local copy of the project for the next steps with the following command:
git clone https://github.com/skandakumaran/fresh_script.git

To set up your credentials, create a new file called credentials.json in the root of the project with the following contents:

{
    "spotify": {
        "username": "[Spotify username]",
        "client_id": "[Spotify client id]",
        "client_secret": "[Spotify client secret]",
        "redirect": "[redirect uri]"
    },
    "reddit": {
        "username": "[reddit username]",
        "client_id": "[praw client id]",
        "client_secret": "[praw client secret]"
    }
}

Installing dependencies

This project uses a dependency manager called pipenv. Follow the instructions to install it here.

The project dependencies are listed in a Pipfile. Using pipenv, you can install all the dependencies with the following commands:

cd fresh_script
pipenv install

Pipenv uses virtualenv to create a python environment with all the dependencies listed in the Pipfile. Before running the fresh.py script, you must first activate the environment:

pipenv shell

If you wish to deactivate the environment use the command

exit

Running the script

Running the program is simple. The first time you run it, you will be asked for your Spotify credientials which will be saved to a config file for ease of use in the future. Choose to sort results by hot or new, enter a post limit, and then enjoy.

python3 fresh.py

Script arguments

The following arguments can be passed to the script

Short Long Type Description
-s --sort string Sort by hot, new, rising, random_rising, controversion or top
-l --limit int How many posts to grab
-t --threshold int Only posts with score above threshold
-f --fresh bool Only add tracks with the [FRESH] tag
-ia --include-albums bool Include tracks from albums
-v --verbose bool Output songs being added and other info
-p --playlists bool List, add, or remove playlists to add songs to

Running the script using cron

We can use cron to automatically run the script periodically in order to keep it up-to-date. You will need either a macOS computer or Linux server to use cron.

  1. Follow the running the script instructions to make sure your .config.ini file is generated with the required parameters
  2. Run crontab -e to open the cron editor, which is similar to vim
  3. Use the following format to create a line for your cron
    * * * * * command to be executed
    - - - - -
    | | | | |
    | | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
    | | | ------- Month (1 - 12)
    | | --------- Day of month (1 - 31)
    | ----------- Hour (0 - 23)
    ------------- Minute (0 - 59)
    
    For example, you would do the following to run this everyday at 9AM
    0 9 * * * python /home/jsmith/fresh.py
    
    • is assumed to mean every sequence of the period. In this instance on minute 0 of hour 9 are specified; however, the day, month, and day of week are *, allowing for the sequence to be automatically ran agnostic of those period changes.

Contributing

I appreciate any help and support. Feel free to fork and create a pull request

fresh_script's People

Contributors

adamfitzgibbon avatar alan-llin avatar amcquade avatar chirag175 avatar degraffm0920 avatar dtcrout avatar emmakingston avatar jb-delafosse avatar joaoppc avatar johncheng2011 avatar matt-degraffenreid avatar ondkloss avatar pricebenjamin avatar roopeshvs avatar sapanpatel123 avatar skandakumaran avatar slammer23 avatar sohilnandu avatar tonydelanuez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fresh_script's Issues

Find a favicon for flask

locate favicon from /r/hiphopheads, then well determine if we want to use that or create something else.

Use cutie for menus

found this really cool menu/user input package cutie and would like to use this for use for things like managing playlists and other things.

Support for adding albums

User should have a choice whether they want to include albums in the set of songs they are adding.

max tracks size

i think there is a limit to how many songs you can add to a playlist in a single request. something should be checking the size of the tracks to make sure it doesnt exceed the limit or somehow create another tracks array to be submitted in an additional request.

`praw.Reddit` instance does not use a unique user-agent

The reddit API rules ask that the supplied user-agent string be

unique and descriptive, including the target platform, a unique application identifier, a version string, and your username as contact information, in the following format:
<platform>:<app ID>:<version string> (by /u/<reddit username>)

Currently, all fresh_script users have the same user-agent, defined by the createPrawConfig function:

fresh_script/fresh.py

Lines 56 to 60 in 29a482a

r_config['bot1'] = {
'client_id': client_id,
'client_secret': client_secret,
'user_agent': 'FreshScript'
}

The createPrawConfig function creates a site_name called 'bot1' in a local praw.ini file. This site_name is then used to create a praw.Reddit instance within main:

reddit = praw.Reddit('bot1')

One solution would be to override the user_agent string when creating the praw.Reddit instance:

user_agent = ' '.join([
    "Python3:FreshScript:(commit 29a482a)",
    "(by /u/<reddit_user>)",
    "(https://github.com/amcquade/fresh_script)"
])
reddit = praw.Reddit('bot1', user_agent=user_agent)

A helper function to generate the user string would be useful. We would also need to store the user's reddit username in one of the configuration files (see #62).

playlist management

give the users ability to add/remove/list the playlists they are submitting tracks to. the easiest way i can think of is by using command arguments, but a menu or something interactive might work better.

move getToken to appropriate location

The User class was moved in #13 but getToken() remains in fresh_script.py. GetToken needs to be either a member function of the User class or refactored and put in the constructor.

Consolidate configuration to a single file

Currently, fresh.py reads from three separate configuration files: .config.ini, credentials.json, and praw.ini.

To make initialization easier for new users, I propose we expect a single configuration file, config.ini (no longer hidden), with the following structure:

[spotify]
username = <username>
client_id = <client_id>
client_secret = <client_secret>
redirect_uri = <redirect_uri>

[reddit]
username = <username>
client_id = <client_id>
client_secret = <client_secret>

Note that we request the reddit username as well. This allows us to create a user-agent string that better follows the reddit API rules. (Better user-agent strings will be requested in a separate issue.)

cron examples

add one or two more examples to the readme of running the script as cron with arguments

set up logging for flask

when the server is running, it should write its outputs to a log file. research how this is done.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.