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)
def insert(item): try: return collection.insert_one(item) except Exception as e: exceptions.handle_error('Failed insert into "posts"', e)
def drop_collection(colName): if colName == "posts": try: return collection.drop() except Exception as e: exceptions.handle_error('Failed to drop "posts"', e)
def batch_insert(items): try: return collection.insert_many(items) except Exception as e: exceptions.handle_error('Failed batch insert into "posts"', e)
def find(query): try: return collection.find(query) except Exception as e: exceptions.handle_error('Failed find in "posts"', e)