Created
January 1, 2016 15:03
-
-
Save LukeB42/adf9caaad15ba1575b1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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