This demo explains how to take a Github repository and deploy it to the world!
- On https://github.com/new, create a new repository (personal, not owned by org) called
lect6
- In Cloud9 terminal, in your home directory, clone the repo:
git clone https://github.com/NJIT-CS490-SP21/lect6-demo-heroku.git
cd
into the repository that is created and you should see all the files now.- Then, connect this cloned repo to your new personal repo made in Step 1:
git remote set-url origin https://www.github.com/{your-username}/lect6
(be sure to change your username and remove the curly braces) - Run
git push origin main
to push the local repo to remote. You should now see this same code in your personallect6
repo.
- Follow the instructions here: https://developer.nytimes.com/get-started (if email verification is showing errors, just refresh the page)
- When creating a New App, make sure you enable Article Search API.
pip install python-dotenv
pip install requests
- Create
.env
file in your project directory - Add your NYT KEY (not Secret!) from https://developer.nytimes.com/my-apps with the line:
export NYT_KEY='YOUR_KEY'
- In
app.py
, change Line 13 to a topic you want to get news about!
- Run command in terminal
python app.py
- Preview web page in browser '/'
- Install Heroku CLI:
npm install -g heroku
. This could take a few minutes. In the meantime... - Create a free account on Heroku https://signup.heroku.com/login
- Create a
requirements.txt
file with all your non-standard dependencies (based on any libraries you are importing), separated by a newline. In our case, they areFlask
w/ a capital F,requests
, andpython-dotenv
. Note that libraries likeos
are standard imports, so they don't need to be included. - Create a
Procfile
, which has the command that Heroku will use to run your app:web: python app.py
(see documentation https://devcenter.heroku.com/articles/getting-started-with-python#define-a-procfile) - Add + commit all changed files with git
- Log in to Heroku:
heroku login -i
- Create a Heroku app:
heroku create
. This will create a new URL and associated host for you. - Push your code to Heroku:
git push heroku main
. This actually pushes your code to Heroku's remote repository. - Open your app with your new URL:
heroku open
. Click the link to open if it doesn't open on its own. It shouldn't work, because it doeesn't have any environment variables (remember, your.env
file is not in your git repository!) - Go to https://dashboard.heroku.com/apps and click your App, then go to Settings, and click "Reveal Config Vars"
- Add your secret key from
.env
with the matching variable name (NYT_KEY
) and value (your key, without quotation marks!) - Run
heroku open
or refresh the URL if you have it open. Voila!