#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Lookup and Store Tweets utility.
"""
import argparse
import os
import sys

# Allow imports to be done when executing this file directly.
sys.path.insert(0, os.path.abspath(os.path.join(
    os.path.dirname(__file__), os.path.pardir, os.path.pardir)
))

from lib import tweets
from lib.twitter import auth

# TODO: Use the sytem category and campaign as set in app.conf file.


def main():
    """
    Command-line interface to lookup and store Tweets.
    """
    parser = argparse.ArgumentParser(
        description="""Lookup and Store Tweets utility. Fetches a tweet from
            the Twitter API given its GUID. Stores or updates the author
            Profile and Tweet in the db."""
        )

    parser.add_argument(
        'tweetGUIDs',
        metavar='TWEET_GUID',
        nargs='+',
        help="""List of one or more Tweet GUIDs to lookup, separated by spaces.
            The Tweet 'GUID' in the local db is equivalent to the Tweet 'ID'
            on the Twitter API.""")

    parser.add_argument(
        '-u', '--update-all-fields',
        action='store_true',
        help="""If supplied, update all fields when updating an existing
            local Tweet record. Otherwise, the default behavior is to
            only update the favorite and retweet counts of the record."""
    )

    args = parser.parse_args()

    APIConn = auth.getAppOnlyConnection()
    tweets.lookupTweetGuids(
        APIConn,
        args.tweetGUIDs,
        onlyUpdateEngagements=not(args.update_all_fields)
    )


if __name__ == '__main__':
    main()

@@ -76,16 +76,183 @@
 utility.
+%0A%0ALookup tweets on Twitter by the GUID and then stores the profile and tweet%0Adata in the local db.%0A%0ATODO: Use the system category and campaign as set in app.conf file.
 %0A%22%22%22%0Aimp
@@ -463,17 +463,16 @@
 dir)%0A))%0A
-%0A
 from lib
@@ -520,78 +520,8 @@
 th%0A%0A
-# TODO: Use the sytem category and campaign as set in app.conf file.%0A%0A
 %0Adef
@@ -564,20 +564,21 @@
 terface 
-to l
+for L
 ookup an
@@ -579,17 +579,17 @@
 kup and 
-s
+S
 tore Twe
@@ -591,16 +591,24 @@
 e Tweets
+ utility
 .%0A    %22%22
@@ -847,25 +847,24 @@
 %22%0A        )%0A
-%0A
     parser.a
@@ -1140,17 +1140,16 @@
 PI.%22%22%22)%0A
-%0A
     pars
@@ -1454,17 +1454,16 @@
 %22%0A    )%0A
-%0A
     args

Update lookupAndStoreTweets.py