Пример #1
0
def delete_intervals(connection: MongoAPI, guild_id: int, interval_id: str = "*"):
    status = 0

    if interval_id == "*":
        status = connection.delete(col_queue, filter_dict={"guild_id": guild_id})
    else:
        status = connection.delete_one(col_queue, filter_dict={"guild_id": guild_id, "interval_id": int(interval_id)})

    if status < 1:
        raise ConnectionError("Failed to delete from queue")
Пример #2
0
def mongo_add_cars(): 
       
    data = request.json
    
    obj1 = MongoAPI(data)
    obj1.populate()
    response = obj1.read()
    
    return Response(response=json.dumps(response),
                    status=200,
                    mimetype='application/json')
Пример #3
0
def mongo_remove():
     
    data = request.json
    
    if data == None or data == {} or 'document' not in data:
        return Response(response=json.dumps({'Error': 'Invalid data request format'}),
                        status=400,
                        mimetype='application/json')
        
    obj1 = MongoAPI(data)
    response = obj1.delete()
    
    return Response(response=json.dumps(response),
                    status=200,
                    mimetype='application/json')
Пример #4
0
def mongo_read():
    
    data = request.json
    
    if data is None or data == {}:
        return Response(response=json.dumps({'Error': 'Invalid data request format'}),
                        status=400,
                        mimetype='application/json')
    
    obj1 = MongoAPI(data)
    response = obj1.read()
    
    return Response(response=json.dumps(response),
                    status=200,
                    mimetype='application/json')
Пример #5
0
def mongo_write():
    
    data = request.json
    
    if data == None or data == {} or 'document' not in data:
        return Response(response=json.dumps({'Error': 'Invalid data request format'}),
                        status=400,
                        mimetype='application/json')
    
    if 'email' in data['document'].keys():
        if Validators.validateEmail(data['document']['email']):
            pass
        else:
            return Response(response=json.dumps({'Error': 'Invalid data request format'}),
                            status=400,
                            mimetype='application/json')
    
    obj1 = MongoAPI(data)
    response = obj1.write()
    return Response(response=json.dumps(response),
                    status=200,
                    mimetype='application/json')        
Пример #6
0
def add_intervals(connection: MongoAPI, guild_id: int, channel: int, interval_id: int, subreddit: str, top_of: int,
                  _time_shift: float, next_post_obj: datetime.datetime):
    data_dict = {
        "guild_id": guild_id,
        "channel": channel,
        "interval_id": interval_id,
        "subreddit": subreddit,
        "top_of": top_of,
        "time_shift": _time_shift,
        "next_post_str": next_post_obj.strftime("%Y.%m.%d_%H:%M"),
        "next_post_obj": next_post_obj
    }

    ret = connection.insert_one(col_queue, data_dict)

    if type(ret) is not ObjectId:
        raise ConnectionError("Failed to insert into queue")
Пример #7
0
def queue_size(connection: MongoAPI):
    return connection.count(col_queue)
Пример #8
0
def next_interval(connection: MongoAPI):
    return connection.find_one(col_queue, filter_dict=None, projection_dict=None, sort=[("next_post_obj", 1)])
Пример #9
0
def time_shift(connection: MongoAPI, queue_entry_mongo_id: ObjectId, new_time_obj: datetime.datetime):
    new_time_str = new_time_obj.strftime("%Y.%m.%d_%H:%M")

    if connection.update_one(col_queue, filter_dict={"_id": queue_entry_mongo_id},
                             update_dict={"$set": {"next_post_obj": new_time_obj, "next_post_str": new_time_str}}) < 1:
        raise ConnectionError("Failed to update queue")
Пример #10
0
def list_all_intervals(connection: MongoAPI):
    intervals = connection.find(col_queue)
    return intervals
Пример #11
0
def list_intervals(connection: MongoAPI, guild_id: int):
    intervals = connection.find(col_queue, {"guild_id": guild_id})
    return intervals
def delete_guild(connection: MongoAPI, guild_id):
    if connection.delete_one(col_servers, {"guild_id": guild_id}) < 1:
        raise ConnectionError("Couldn't delete server")
Пример #13
0
# ======================================================================================================================
# globals
# ======================================================================================================================
f_updated = False
size_limit = 50
running = False
time_spans = ('hour', 'day', 'week', 'month', 'year', 'all')
current_version = 4.3

debugging = False

logging.basicConfig(filename="RedditTopOfBot.log",
                    format='%(asctime)-15s %(message)s')

mapi = MongoAPI(db_name, db_username, db_password)

# ======================================================================================================================
# Utils
# ======================================================================================================================


def poc(string):
    """
    Debugging Aid, Prints a string to the cli if the GLOBAL VARIABLE 'debugging' is true

    :param string: string to print
    :return:
    """

    if debugging: