Skip to content
This repository has been archived by the owner on Dec 8, 2017. It is now read-only.

Commit

Permalink
starting python development
Browse files Browse the repository at this point in the history
  • Loading branch information
EricSchles committed Feb 9, 2017
1 parent 03ee1d7 commit 8646b65
Show file tree
Hide file tree
Showing 197 changed files with 32,580 additions and 39 deletions.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn app:app
102 changes: 63 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,77 @@
[![Build Status](https://travis-ci.org/18F/team-browser.svg?branch=master)](https://travis-ci.org/18F/team-browser)
[![Code Climate](https://codeclimate.com/github/18F/team-browser/badges/gpa.svg)](https://codeclimate.com/github/18F/team-browser)
[![Test Coverage](https://codeclimate.com/github/18F/team-browser/badges/coverage.svg)](https://codeclimate.com/github/18F/team-browser)
# News Literacy Project Website

A human-friendly web interface to the [data](https://team-api.18f.gov/public/api/) served by the [Team API Server](https://github.com/18f/team-api-server). For now the browser reads only public data.
[Dev website](http://thenewsliteracyproject.herokuapp.com/)

## Serving locally
## Installation

You will need [Ruby](https://www.ruby-lang.org) version 2.1.5 or greater and [Bundler](http://bundler.io/). You'll also need to set a local environment variable `HMAC_KEY` with an HMAC key from the team-api-server.
The first thing you'll need to do is clone this repo, it's preferred that you fork it and then submit pull requests from your fork. This way we have clear providence of who did what, but also, it will be easier to roll back changes, should something be wrong, before committing to the canonical master repository.

To run your own local instance at `http://localhost:4000`:
You'll need [Python 3](https://www.python.org/downloads/) (Python 3.5 is preferred), [pip3](https://pip.pypa.io/en/stable/) (1.8.2 is preferred), and the heroku toolbelt and a heroku account to deploy this repository.

```
$ git clone https://github.com/18F/team-browser.git
$ cd team-browser
$ cp set_hmac_auth.sample.sh set_hmac_auth.sh
$ nano set_hmac_auth.sh # or your favorite editor; set `HMAC_KEY`
$ source set_hmac_auth.sh
$ ./go serve
```
After you install Python simply run:

### Serving from Vagrant
`pip install -r requirements.txt` (which is found in the top level directory of the main repo)

As above, but also
If you have python 2 installed, you might need to do:

- Add `config.vm.network "forwarded_port", guest: 4000, host: 4000` to your `Vagrantfile`
- Run with `./go serve --host 0.0.0.0`
`pip3 install -r requirements.txt`

## Contributing
Everything regarding deploying to heroku should be in

1. Fork the repo (or just clone it if you're an 18F team member)
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Make your changes and test them via `./go test`
4. Commit your changes (`git commit -am 'Add some feature'`)
5. Push to the branch (`git push origin my-new-feature`)
6. Create a new Pull Request
`setup.md` (in the base directory).

Feel free to [file an issue](https://github.com/18F/team-browser) or to ping the #hub channel in 18F's Slack with any questions you may have,
especially if the current documentation should've addressed your needs, but
didn't.
To migrate the database, please see:

## Public domain
`manager.py` (in the base directory).

This project is in the worldwide [public domain](LICENSE.md). As stated in
[CONTRIBUTING](CONTRIBUTING.md):
## Contribution

> This project is in the public domain within the United States, and copyright
> and related rights in the work worldwide are waived through the
> [CC0 1.0 Universal public domain dedication](https://creativecommons.org/publicdomain/zero/1.0/).
>
> All contributions to this project will be released under the CC0 dedication.
> By submitting a pull request, you are agreeing to comply with this waiver of
> copyright interest.
To contribute to this application, please fork from the canonical master and create pull requests.

To configure a remote for a fork:

* `git remote add upstream https://github.com/18F/SkillShare.git`
* For more: https://help.github.com/articles/configuring-a-remote-for-a-fork/

To sync a fork

* `git fetch upstream`
* `git pull`
* `git checkout master` (or whatever branch)
* For more: https://help.github.com/articles/syncing-a-fork/

To make a pull request

* `git pull origin master`
* Go to main repository and create a pull request

### Troubleshooting

## Unable to create db

If you try creating a db:
* `createdb skills_admin`

and you get:

```
createdb: could not connect to database template1: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
```

Try:
* `pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start`

You might also need to do:

`rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8` which comes from [https://github.com/Homebrew/legacy-homebrew/issues/35240](https://github.com/Homebrew/legacy-homebrew/issues/35240)
## Unable to install pyscopg2

Try installing xcode-setup and re-run the Installation

Please see here: http://stackoverflow.com/questions/33866695/install-psycopg2-on-mac-osx-10-9-5-pg-config-pip

##JavaScript Library

We are using [moment.js](https://momentjs.com/) to get the local timezone for the user as a fallback in case we cannot create a date object on the frontend. The minified version of the code exists in `app/static/js/moment.min.js`.
22 changes: 22 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from flask import Flask
from flask_script import Manager
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate, MigrateCommand
from flaskext.markdown import Markdown
from .commands import REPL
import os

app = Flask(__name__)
username="news_literacy_admin"
password="1234"
#app.config["SQLALCHEMY_DATABASE_URI"] = os.getenv("DATABASE_URL")
app.config["SECRET_KEY"] = "testing"
app.config["SQLALCHEMY_DATABASE_URI"] = "postgres://"+username+":"+password+"@localhost/news_literacy_db"
db = SQLAlchemy(app)
migrate = Migrate(app,db)
manager = Manager(app)
manager.add_command('db',MigrateCommand)
manager.add_command("shell",REPL())
markdown = Markdown(app)

from app import views, models
Binary file added app/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
Binary file added app/__pycache__/commands.cpython-35.pyc
Binary file not shown.
Binary file added app/__pycache__/models.cpython-35.pyc
Binary file not shown.
Binary file added app/__pycache__/views.cpython-35.pyc
Binary file not shown.
Binary file added app/__pycache__/viz.cpython-35.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions app/blog_entries/hellothere.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#Schools are doing better with NLP!

This school is totally doing better
3 changes: 3 additions & 0 deletions app/blog_entries/whatever.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#Hello there

lets thinking critically
8 changes: 8 additions & 0 deletions app/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from flask_script import Command
import code

class REPL(Command):
"runs the shell"

def run(self):
code.interact(local=locals())
128 changes: 128 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
"""
Here the models for our database is defined.
I am using Postgres, Flask-SQLAlchemy for this application.
For an introduction to Flask-SQLAlchemy check out: http://flask-sqlalchemy.pocoo.org/2.1/
__init__ function for each model is a constructor, and is necessary to enter
"""
from app import db

class Users(db.Model):
"""
This model gives us a set of specific information for each user in this application
parameters:
@name - the persons name; in order first, last
@email - the person's gsa email
functions:
__str__ - Returns the user name and password as an formatted string <Id: id, Username: username>
"""
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String)
email = db.Column(db.String,unique=True)
t = db.Column(db.Integer)

def __init__(self,name,email, t):
self.name = name
self.email = email
self.t = t

def __str__(self):
return "<name: {}, email:{}>".format(self.name,self.email)

# ToDos:
# * Add location lookup support
class SiteVisits(db.Model):
"""
This gives us impression information about a given page on the website
parameters:
@page_name - The route name of the page being visited
@from_page - A json blob with every other page on the website and the frequency of visiting this page from those pages
@to_page - A json blob with every other page on the website and the frequency of visiting those pages from this one
@overall_frequency - The frequence that a page is visited
@monday_frequency - frequency on mondays
@tuesday_frequency - frequency on tuesdays
@wednesday_frequency - frequency on wednesdays
@thursday_frequency - frequency on thursdays
@friday_frequency - frequency on fridays
@saturday_frequency - frequency on saturdays
@sunday_frequency - frequency on sundays
@weekday_frequency - frequency during the week
@weekend_frequency - frequency during the weekend
@morning_frequency - frequency in the morning, 5am - 11am
@midday_frequency - frequency in during the day - 11am - 5pm
@afterwork_frequency - frequency after work - 5pm - 9pm
@latenight_frequency - frequency late night - 9pm - 5am
@frequency_from_other_pages - a dictionary from another page on the website
functions:
__str__ - Returns the user name and password as an formatted string <Id: id, Username: username>
"""
__tablename__ = 'site_visits'
id = db.Column(db.Integer, primary_key=True)
page_name = db.Column(db.String)
from_page = db.Column(db.String)
to_page = db.Column(db.String)
overall_frequency = db.Column(db.Integer)
monday_frequency = db.Column(db.Integer)
tuesday_frequency = db.Column(db.Integer)
wednesday_frequency = db.Column(db.Integer)
thursday_frequency = db.Column(db.Integer)
friday_frequency = db.Column(db.Integer)
saturday_frequency = db.Column(db.Integer)
sunday_frequency = db.Column(db.Integer)
weekday_frequency = db.Column(db.Integer)
weekend_frequency = db.Column(db.Integer)
morning_frequency = db.Column(db.Integer)
midday_frequency = db.Column(db.Integer)
afterwork_frequency = db.Column(db.Integer)
latenight_frequency = db.Column(db.Integer)
frequency_from_other_pages = db.Column(db.String)


def __init__(
self,
page_name,
from_page,
to_page,
overall_frequency,
monday_frequency,
tuesday_frequency,
wednesday_frequency,
thursday_frequency,
friday_frequency,
saturday_frequency,
sunday_frequency,
weekday_frequency,
weekend_frequency,
morning_frequency,
midday_frequency,
afterwork_frequency,
latenight_frequency,
frequency_from_other_pages
):
self.page_name = page_name
self.from_page = from_page
self.to_page = to_page
self.overall_frequency = overall_frequency
self.monday_frequency = monday_frequency
self.tuesday_frequency = tuesday_frequency
self.wednesday_frequency = wednesday_frequency
self.thursday_frequency = thursday_frequency
self.friday_frequency = friday_frequency
self.saturday_frequency = saturday_frequency
self.sunday_frequency = sunday_frequency
self.weekday_frequency = weekday_frequency
self.weekend_frequency = weekend_frequency
self.morning_frequency = morning_frequency
self.midday_frequency = midday_frequency
self.afterwork_frequency = afterwork_frequency
self.latenight_frequency = latenight_frequency
self.frequency_from_other_pages = frequency_from_other_pages


def __str__(self):
return "<name: {}, email:{}>".format(self.name,self.email)
Loading

0 comments on commit 8646b65

Please sign in to comment.