Skip to content

Instantly share code, notes, and snippets.

@LukeB42
Created January 1, 2016 15:03
Show Gist options
  • Save LukeB42/adf9caaad15ba1575b1b to your computer and use it in GitHub Desktop.
Save LukeB42/adf9caaad15ba1575b1b to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# _*_ coding: utf-8 _*_
#
# Usage: emrange int:start int:stop
# Examples: emrange ; Display the total number of articles
# emrange -5 ; Display the last five articles
# emrange 0 5 ; Display the first five articles
#
import sys
from emissary.models import Article
def emrange(x, y=None):
if y:
articles = Article.query.all()[x:y]
else:
articles = Article.query.all()[x:]
articles.reverse()
for a in articles:
print a.uid, a.title
if __name__ == "__main__":
if len(sys.argv) == 1:
print len(Article.query.all())
elif len(sys.argv) == 2:
emrange(int(sys.argv[1]))
elif len(sys.argv) == 3:
emrange(int(sys.argv[1]), int(sys.argv[2]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment