Make a lil post on mattermost when we find a new valid report

This commit is contained in:
mcbloch 2022-10-06 23:07:26 +02:00
parent bbfa219008
commit a5bbd9462b
3 changed files with 27 additions and 6 deletions

View file

@ -54,10 +54,17 @@ def get_discovered_files() -> List[str]:
return discovered_files
def add_valid_file(filename, metadata):
def add_valid_file(filename, metadata) -> bool:
"""
Returns: Boolean that indicates if the file is newly identified as valid.
"""
db = _load_db()
valid_files = db.get("valid_files", {})
new_file = False
if filename not in valid_files:
new_file = True
valid_files[filename] = metadata
db["valid_files"] = valid_files
_save_db(db)
return valid_files
return new_file

View file

@ -12,7 +12,7 @@ from colored import style
from mattermostdriver import Driver
from tabulate import tabulate
from MattermostObjects import MMUser, MMPost, MMChannelPosts
from mattermost_objects import MMUser, MMPost, MMChannelPosts
from utils import humanize_date_difference, timer
pp = pp.PrettyPrinter(indent=2)
@ -81,6 +81,7 @@ def merge_dict(a: dict, b: dict) -> dict:
class MMApi(Driver):
def __init__(self, user: User = users["flynn"]):
print(f"Initializing MMApi client for user {user}")
Driver.__init__(
self,
merge_dict(
@ -109,7 +110,7 @@ class MMApi(Driver):
print(f"{style.BOLD}[{log_level.value}]{style.RESET} {text}")
def get_channel_id(self, channel_name):
resp = self.channels.get_channel_by_name(self.team_id, channel_name, since)
resp = self.channels.get_channel_by_name(self.team_id, channel_name)
id = resp["id"]
self.log(f"Fetching channel id for {channel_name}: {id}")
return id

View file

@ -8,7 +8,8 @@ import requests
import db
import dir_utils
from mattermost import MMApi
from mattermost import MMApi, ChannelApi
import mattermost
def find_codimd_files_on_mattermost():
@ -54,6 +55,16 @@ def download_files():
print(f"Downloading url {url}")
f.write(read_note(url))
def filename_to_url(filename):
return f"https://codimd.zeus.gent/{filename[5:-3]}"
def report_newly_found_file(filename):
channel = ChannelApi("bestuur-dev", mattermost.users["flynn"])
channel.create_post(
f"I found a new report: {filename_to_url(filename)}! Making work of putting it on gitlab :)"
)
def validate_downloaded_files():
path = "data"
@ -62,7 +73,9 @@ def validate_downloaded_files():
for filename in dir_list:
metadata = dir_utils.find_metadata("data/" + filename)
if metadata is not None:
db.add_valid_file(filename, metadata)
is_new_file = db.add_valid_file(filename, metadata)
if is_new_file:
report_newly_found_file(filename)
return db._load_db()