Skip to content

A simple screen capture API based on PhantomJS, CasperJS, Redis, RQ, Flask, Gunicorn and good intentions.

License

Notifications You must be signed in to change notification settings

pombredanne/moment-1

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Moment

Note: 31/3/2014 - I'm working on a greatly enhanced version of Moment. The current code works well for what it does and is free for forking. This repo will be updated in the nearish future.

A simple screen capture API based on PhantomJS, CasperJS, Redis, RQ, Flask, Gunicorn and good intentions...

We're just sitting on the shoulders of giants.

Contributing

Please help:

The goal of Moment is a simple, easy to deploy and use, API for screen captures.

The feature set will remain minimal, and the code should be clean and highly readable.

We'd like to complete the following, and only the following, to be feature complete for V1:

  • Expose RESTful API endpoints for users
  • Create a UI for user accounts
  • Implement a simple and elegant looking solution for watermarking images with their source URL and any license declaration
  • Implement a proper backup and restore mechanism for the Redis database
  • Implement image cropping
  • Expose 'delay' and 'event' arguments for the capture method

Capturing

We did have a demo setup with a test user. Please make some test captures, and if you have any issues, please file a bug.

Here are the temporary credentials:

  • username: test_user
  • key: c413c0979c2c42bbbc1adb3c55797851
  • token: 6cdf4a492ecd4500ec80b6f4d95d0529

The current status of the code exposes a simple capture API - you pass a set of valid parameters, and you get back a file in return. Some parameters are required, and the rest have sensible defaults.

Required

  • user: the user's key
  • token: the user's token
  • url: the URL to capture

Optional

  • format: 'png' or 'pdf'. 'png' default.
  • viewport: 'width,height'. '1280,800' default.
  • target: 'element' or '#id' or '.class'. 'body' default.
  • and more to be documented.....

Note:

If you need to use '?' or '#' symbols as values in the query - that is fine, just make sure they are encoded.

  • ? : %3F
  • # : %23

Examples

Some example captures (no longer working):

Setting up an instance

  • Make sure you have Python, CasperJS, PhantomJS and Redis available on your system
  • Create a virtualenv called moment, in your preferred way
  • Clone the repo into your project folder: e.g: git clone git@github.com:pwalsh/moment.git.
  • Install the pip-managed requirements: pip install -r -U requirements.txt
  • Run the server. You can run Flask's development server for debugging with: python dev.py from the project root. Alternatively, Run Gunicorn with gunicorn moment:app
  • Visit 127.0.0.1:9000 in your browser.
  • Currently, only the /capture/ endpoint is implemented. This is a convenience endpoint that any user can hit with a set of parameters, and have a file returned. See examples above for how to construct a query to /capture.

Create a user

There is no web API for creating a user at present. To create user's on your own Moment instance, call the create_user function from Python like so:

>>> from moment.models import create_user
>>> u = create_user(username="username")

create_user returns a tuple of the user's key and token.

The user's key is of the format "moment,user,UUID" (that's a string, used as a redis key).

On the /capture/ endpoint, you only use the UUID part of the user's key for the ?user parameter.

Database

Moment uses Redis as a database. This makes serving very fast (after the first capture), but it does mean that the data is modeled in a way that may seem unusual when coming from a relational database perspective.

The keys for our data do use keywords to identify the modeled data they contain.

The following pattern is implemented:

Project namespace

Set with the REDIS_KEY_PREFIX variable in the project configuration.

The

About

A simple screen capture API based on PhantomJS, CasperJS, Redis, RQ, Flask, Gunicorn and good intentions.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 91.0%
  • JavaScript 9.0%