# Path: newsApp/cachingHelper.py
# def getCache():
#   servers = os.environ.get('MEMCACHIER_SERVERS', '').split(',')
#   user = os.environ.get('MEMCACHIER_USERNAME', '')
#   passw = os.environ.get('MEMCACHIER_PASSWORD', '')
# 
#   return bmemcached.Client(servers, user, passw)
# 
# Path: newsApp/constants.py
# LINKTAG_PUBTIME = 'pubtime'
# 
# FEEDTAG_DO_NOT_CLUSTER = 'doNotCluster'
# 
# Path: newsApp/dbhelper.py
# def parseConnectionString(connectionString):
#     """
#     Parses the table connection string. Returns a dict of parameters found.
#     """
# 
#     return dict(item.split('=') for item in connectionString.split(';'))
# 
# def getS3Connection(connectionString):
#     connectionParams = parseConnectionString(connectionString)
# 
#     connection = S3Connection(
#         connectionParams['accessKeyId'],
#         connectionParams['secretAccessKey'])
# 
#     return connection
# 
# Path: newsApp/doc.py
# class Doc:
#   """
#   Represents a document.
# 
#   Each doc consists of an auto-generated id, original, processed content
#   and some tags(which are key-value pairs to help in clustering).
#   """
# 
#   def __init__(self, key, content, tags):
#     """
#     Instantiates a new document object.
# 
#     """
# 
#     self.key = key.upper();
#     self.content = content;
#     self.tags = tags;


import os
import json
import calendar
import time
from boto.s3.connection import S3Connection
from boto.s3.key import Key
from .cachingHelper import getCache
from .constants import LINKTAG_PUBTIME, FEEDTAG_DO_NOT_CLUSTER
from .dbhelper import parseConnectionString, getS3Connection
from .doc import Doc



def _getEpochSecs(t):
    return calendar.timegm(time.strptime(t[:19], "%Y-%m-%dT%H:%M:%S"))

class DocManager:
    """
    Manage documents stored in cloud.

    Contains functions for CRUD operations on documents
    """

    def __init__(self):
        """
        Instantiates a new instance of DocManager class

        'bucketConnString' : connection string of s3 bucket in which docs
        are stored.
        """

        self.bucketConnString = os.environ['DOCSBUCKET_CONNECTIONSTRING']
        self.cache = getCache()
        self.__cacheExpiry= 900

    def __getBucket(self):
        bucketConnParams = parseConnectionString(self.bucketConnString)

# Path: newsApp/cachingHelper.py
# def getCache():
#   servers = os.environ.get('MEMCACHIER_SERVERS', '').split(',')
#   user = os.environ.get('MEMCACHIER_USERNAME', '')
#   passw = os.environ.get('MEMCACHIER_PASSWORD', '')
# 
#   return bmemcached.Client(servers, user, passw)
# 
# Path: newsApp/constants.py
# LINKTAG_PUBTIME = 'pubtime'
# 
# FEEDTAG_DO_NOT_CLUSTER = 'doNotCluster'
# 
# Path: newsApp/dbhelper.py
# def parseConnectionString(connectionString):
#     """
#     Parses the table connection string. Returns a dict of parameters found.
#     """
# 
#     return dict(item.split('=') for item in connectionString.split(';'))
# 
# def getS3Connection(connectionString):
#     connectionParams = parseConnectionString(connectionString)
# 
#     connection = S3Connection(
#         connectionParams['accessKeyId'],
#         connectionParams['secretAccessKey'])
# 
#     return connection
# 
# Path: newsApp/doc.py
# class Doc:
#   """
#   Represents a document.
# 
#   Each doc consists of an auto-generated id, original, processed content
#   and some tags(which are key-value pairs to help in clustering).
#   """
# 
#   def __init__(self, key, content, tags):
#     """
#     Instantiates a new document object.
# 
#     """
# 
#     self.key = key.upper();
#     self.content = content;
#     self.tags = tags;


# Path: newsApp/docManager.py
import os
import json
import calendar
import time
from boto.s3.connection import S3Connection
from boto.s3.key import Key
from .cachingHelper import getCache
from .constants import LINKTAG_PUBTIME, FEEDTAG_DO_NOT_CLUSTER
from .dbhelper import parseConnectionString, getS3Connection
from .doc import Doc




def _getEpochSecs(t):
    return calendar.timegm(time.strptime(t[:19], "%Y-%m-%dT%H:%M:%S"))

class DocManager:
    """
    Manage documents stored in cloud.

    Contains functions for CRUD operations on documents
    """

    def __init__(self):
        """
        Instantiates a new instance of DocManager class

        'bucketConnString' : connection string of s3 bucket in which docs
        are stored.
        """

        self.bucketConnString = os.environ['DOCSBUCKET_CONNECTIONSTRING']
        self.cache = getCache()
        self.__cacheExpiry= 900

    def __getBucket(self):
        bucketConnParams = parseConnectionString(self.bucketConnString)

        conn = getS3Connection(self.bucketConnString)