Permalink
Browse files

server: Check if the script is run as main.

Also deletes some trailing whitespaces.
  • Loading branch information...
1 parent ebdb41d commit 93b64b296b0a27130613f0597de916d6e45c38e2 @lionaneesh lionaneesh committed Mar 16, 2012
Showing with 25 additions and 24 deletions.
  1. +25 −24 ghettorss-server.py
View
@@ -118,13 +118,13 @@ def do_GET(self):
db = connect_to_database()
cursor = db.cursor()
cursor.execute("""
- SELECT
- feeds.id AS feed_id,
- feeds.title AS feed_title,
+ SELECT
+ feeds.id AS feed_id,
+ feeds.title AS feed_title,
COUNT(feeds.id) AS unread_count
- FROM feeds
- INNER JOIN posts
- ON posts.feed_id=feeds.id
+ FROM feeds
+ INNER JOIN posts
+ ON posts.feed_id=feeds.id
GROUP BY feeds.id
""")
# There must be a more elegant way to convert this
@@ -162,10 +162,10 @@ def do_GET(self):
db = connect_to_database()
cursor = db.cursor()
cursor.execute("""
- SELECT
+ SELECT
id AS post_id, title, author, date, timestamp, read
FROM posts
- WHERE feed_id=?
+ WHERE feed_id=?
""", (feed_id,))
# SQLite -> Python data structure, so that easy JSON
# serialization is possible later
@@ -206,21 +206,22 @@ def usage():
-p, --port=[number]: Port on which to run the HTTP server
"""
-port = DEFAULT_HTTP_PORT
-# process command line arguments
-opts, args = getopt.getopt(sys.argv[1:], "hp:", ["help", "port="])
-
-for opt, arg in opts:
- if opt in ("-h", "--help"):
- usage()
- sys.exit()
- elif opt in ("-p", "--port"):
- try:
- port = int(arg)
- except ValueError:
- print "Invalid port number"
- sys.exit()
+if __name__ == '__main__':
+
+ port = DEFAULT_HTTP_PORT
+ # process command line arguments
+ opts, args = getopt.getopt(sys.argv[1:], "hp:", ["help", "port="])
-# kick off the server
-run(port)
+ for opt, arg in opts:
+ if opt in ("-h", "--help"):
+ usage()
+ sys.exit()
+ elif opt in ("-p", "--port"):
+ try:
+ port = int(arg)
+ except ValueError:
+ print "Invalid port number"
+ sys.exit()
+ # kick off the server
+ run(port)

0 comments on commit 93b64b2

Please sign in to comment.