예제 #1
0
def get_posts(sub, symbol, classifier, sort="new"):
    url = f'{baseURL}{sub}/search.json'
    params = {'q': symbol, 'sort': sort}
    try:
        resp = requests.get(url=url, params=params, headers=headers)
        if resp.status_code == 200:
            return __process_posts(resp.json(), classifier)
        else:
            exceptions.handle_error("Failed to get reddit posts.",
                                    str(resp.status_code))
    except Exception as e:
        exceptions.handle_error("Failed to get reddit posts.", e)
예제 #2
0
def insert(item):
    try:
        return collection.insert_one(item)
    except Exception as e:
        exceptions.handle_error('Failed insert into "posts"', e)
예제 #3
0
def drop_collection(colName):
    if colName == "posts":
        try:
            return collection.drop()
        except Exception as e:
            exceptions.handle_error('Failed to drop "posts"', e)
예제 #4
0
def batch_insert(items):
    try:
        return collection.insert_many(items)
    except Exception as e:
        exceptions.handle_error('Failed batch insert into "posts"', e)
예제 #5
0
def find(query):
    try:
        return collection.find(query)
    except Exception as e:
        exceptions.handle_error('Failed find in "posts"', e)