-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage_queue.py
More file actions
35 lines (25 loc) · 838 Bytes
/
message_queue.py
File metadata and controls
35 lines (25 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
import pandas as pd
from os import path
from datetime import datetime
CSV_DIR = 'csv'
FILE_NAME = 'queue'
if not path.isdir(CSV_DIR):
os.makedirs(CSV_DIR)
class MessageQueue:
def __init__(self):
self.file_path = f'{CSV_DIR}/{FILE_NAME}.csv'
print(self.file_path)
if path.exists(self.file_path):
self.df = pd.read_csv(self.file_path, index_col=0)
self.df.index = pd.to_datetime(self.df.index)
else:
self.df = pd.DataFrame(columns=['message_id', 'channel_id'])
def __del__(self):
print(self.file_path)
self.df.to_csv(self.file_path)
def add(self, message_id, channel_id):
now = pd.to_datetime(datetime.now())
self.df.loc[now] = [message_id, channel_id]
def show(self):
print(self.df)