Post SpotPosts at cool spots.
- Install python2.7 (might work with python3) and virtualenv
- Make a directory for the project and go into it
- Run
git clone
with the git url - Make a directory called
venv
inside here - Run
virtualenv venv
- Run
. venv/bin/activate
(orvenv\scripts\activate
for Windows) - Run
pip install flask
- If you are done, run
deactivate
to exit the virtual environment
- Go to project directory
- Run
. venv/bin/activate
- Enter the git repo directory
- Run
python main.py
You will now have a server running on localhost:5000
that you can access in
your web browser. Feel free to do development and make commits inside the
virtual environment.
- Run
deactivate
to exit the virtual environment
/var/www/spotpost/
(main directory for spotpost)README.md
(Readme that has instructions for updating deployment server)spotpost.wsgi
(Python script that is run by apache to connect to Flask using WSGI)venv/
(virtualenv folder, seegit/README.md
)
/var/www/spotpost/git/
(git repo for SpotPost)spotpost_log
(a log file for Flask used in deployment)README.md
(Another readme file)
/etc/httpd/conf.d/spotpost.conf
(The apache config for WSGI virtual host)/var/log/httpd/error_log
(apache error log, will need to be root)
- Any errors should be written to a
spotpost_log
file in thegit
directory - Be careful when letting sqlite create the database from scratch. The permissions may not be correct for the deployment server (needs to be group writable). Also the directory the database is in needs to be group writable
- Simply run
python testdata.py
- This will empty the tables and add in test data.
- This should work now, if it errors out, run it again. Im still looking of how to fix this bug but it doesn't happen more than once.
- Send a
POST
request to/_register
containing the user's info. /_register
will NOT accept get requests.- We are assuming
login.html
willPOST
registration information here. - User's info is expected as a JSON following this format:
username
: Username to register.password
: Password of new user.
- Server will store the password encrypted using SHA256-encrypt.
- Priviledge of user is automatically set to 0, as in regular user priveledges.
- This will log the person in once they have registered.
- Send a
POST
request to/login
containing the user's info. - A
GET
request will redirect the user to the login form contained insidelogin.html
. - It is assumed
login.html
will be the one to send aPOST
to/login
. - User's info is expected as a JSON following this format:
username
: Username of user.password
: User's password.
- User will be pushed onto session object.
- Only admin's may promote a user to be an admin.
- In order to promote a user go to
/promote/<username>
, where<username>
is the user to be promoted. - This will make a user an admin. If they already are an admin nothing happens.
- Simply navigate to
/_logout
. - This will pop the user from the session.
- In order to obtain a spotpost a GET request must be made to
www.spotpost.me/spotpost/_get
. - This will return a JSON file containing either all Spotposts, or Spotposts based on your search parameters.
- To add search parameters add
?<parameter name> = <parameter value>
to the url for the first parameter. for more parameters add&<parameter name> = <parameter value>
. - Jquery can do this for you using
.getJSON()
if possible find an alternative using whatever JS you use. - List of possible parameters, replace
<parameter name>
from above with this.min_reputation
: Minimum rating of Spotpost to search for.max_reputation
: Maximum rating of Spotpost to search for.username
: Author of Spotpost to search for.id
: ID of Spotpost. This overrides the other search parameters.lock_value
: Lock value of your search.- A
lock_value
of 0 gets you all SpotPosts. Therefore this is the default value. - A
lock_value
of 1 gets you all LOCKED SpotPosts. - A
lock_value
of 2 gets you all UNLOCKED SpotPosts.
- A
unlock_posts
: Value determining whether to unlock posts returned.- A value of 0 or no value does NOT unlocks posts.
- Any other value will unlock posts.
- JSON contains an array of Spotposts based on your search parameters.
- Each Spotpost is constructed as follows.
id
: ID of Spotpost.content
: Content of Spotpost.title
: Title of Spotpost.reputation
: Rating of Spotpost.longitude
: Longitude of Spotpost.latitude
: Latitude of Spotpost.user
: A dictionary containing the following.username
: Name of user who posted the Spotpost.reputation
: Reputation of users who posted the Spotpost.
comments
: Array of comments, where each comment contains the following.id
: ID of comment.message_id
: Spotpost ID of the spotpost the comment is from.content
: Content of the comment.username
: Username of person who posted comment.time
: Date and Time comment was posted.
time
: Date and Time Spotpost was posted.
- To get spotposts by a certain location you must make a
GET
request to/spotpost/_getlocation
- This will return a JSON object containing the top posts in an area, all specified by you.
- It uses a scoring algorithm similar to reddit's.
- Parameters are required to use this functionality. Parameters are outlined below. Parameters must also be appended to the end of a URL using
?parameter1=x¶meter2=y
notation.latitude
: Latitude of center point.longitude
: Longitude of center point.radius
: radius of circle to look inside of in meters. DEFAULT = 100 Meters.top_count
: Number of top spotposts to return. DEFAULT = 10.
- Returned Spotposts follow the exact same convention as getting spotposts above.
- In order to post a SpotPost you must make a
POST
request to/spotpost/_post
. - You must send a JSON file containing the data associated with the SpotPost.
- Format the JSON using the following form.
- Please note that required parameters are marked with a *.
- *
content
: content of SpotPost. - *
latitude
: latitude position of SpotPost. - *
longitude
: longitude position of SpotPost. username
: Username of user who posted the SpotPost. Default is the current logged in user.reputation
: Custom starting reputation of SpotPost. Default is 0.- *
title
: Title of Spotpost.
- *
- You must be logged in as an admin to update spotposts.
- In order to update you must make a
POST
request to/spotpost/_update
. - You must also send a JSON file containing the data associated with the SpotPost.
- Format the JSON in the following way.
- The ID field is REQUIRED, however all the others are optional, but you must include one at least.
id
: id of SpotPost.content
: content of SpotPost.latitude
: latitude position of SpotPost.longitude
: longitude position of SpotPost.username
: Username of user who posted the SpotPost. Default is the current logged in user.reputation
: Custom starting reputation of SpotPost. Default is 0.
- You must be logged in as a valid user to do this.
- Go to
/spotpost/_upvote/<id>
. Replace<id>
with the ID of the Spotpost you are upvoting. <id>
must be a valid ID. Users can only vote on any given Spotpost once.- There is minimal error checking, it won't crash the server though.
- Same procedure and rules as Upvoting.
- However, you must go to
/spotpost/_downvote/<id>
instead. Replace<id>
with the ID of the Spotpost.
- In order to post a comment you must make a
POST
request to/comment/_post
. - You must send a JSON file containing the data associated with the comment.
- Please note that required parameters are marked with a *.
- *
message_id
: ID of the spotpost the comment is from. - *
content
: Content of the comment. username
: Username of user who posted the comment. Default is the current logged in user.reputation
: Custom starting reputation of comment. Default is 0.
- *
- You must be logged in as a valid user to do this.
- Go to
/comment/_upvote/<id>
. Replace<id>
with the ID of the comment you are upvoting. <id>
must be a valid ID. Users can only vote on any given comment once.- There is minimal error checking, it won't crash the server though.
- Same procedure and rules as Upvoting.
- However, you must go to
/comment/_downvote/<id>
instead. Replace<id>
with the ID of the comment.
- Must be logged in as Admin to do this.
- Go to
/spotpost/_delete/<id>
. - Replace
<id>
with the ID of the spotpost you want to delete
- Go to
/_follow/<username>
where<username>
is the username of the person being followed. - This will make the current logged in user follow
<username>
. - This accounts for duplicates and will prevent users from double following.
- Go to
/_unfollow/<username>
where<username>
is the username of the person being followed. - This will make the current logged in user unfollow
<username>
.
- Go to
/followerlist/<username>
where<username>
is the username of the person being followed. - This will return a JSON file containing an array of usernames.
- In the future it will return an array of user arrays like
get_spotpost
does currently.
On every interaction with the server you will get a JSON back. With at least an error
field containing the following:
code
: Integer number pertaining to the errormessage
: String containing a short description about the error.
While you will always get a message with the code I thought I would put what each code means for checking purposes and just in case. If an error is described here, you can assume it is implemented in the server and will be thrown when appropriate. Every use of the API will return an error JSON. The JSON structure is as follows:
error
:another json as described below.
code
:Numerical code pertaining to this error.
message
:Short description of the error.
Key: code
: description
1000
:Success.
1032
:Admin privileges required.
1050
:Invalid login information.
1055
:Username already in use.
1087
:Not logged in.
1092
:Location Data not Provided.
- Placeholder!
These SHOULDN'T occur and will only occur if something went haywire with the API.
9110
=User doesn't exist.
- PLACEHOLDER
This is where I will write basically what HTML pages the server expects and what each page does. If I am wrong with what you designed notify me and I will change. Put simply this is what the server thinks its seeing and doing.
login.html
, A login page toPOST
login's andPOST
new registrations.index.html
, The main page where all other operations occur.admin.html
, A possible admin page which allows admins to use tools in the API.
Format is Name : Password
Admin privilege enabled.
Admin : BananaPeppers
Crud Bonemeal : Protein
SomeDude : Garbage
Phillabuster : Freaks812
Tester : Dijkstra
Lurker : NoPost