def update_messages_nodes(self, groupme: GroupMe): before_id = -1 new_last_message = -1 print('Updating messages', end='') messages = groupme.get_messages() while messages is not None: for message in messages: properties = "{" for key, value in message.items(): if key != "attachments" and key != "event" and value is not None: properties += f"{key}: {repr(value)}, " properties = properties[:-2] + "}" query = f"merge (m:Message {properties})" self.graph.run(cypher=query) new_last_message = max(new_last_message, int(message["id"])) before_id = int(messages[-1]["id"]) if int(messages[-1]["id"]) < self.last_message: break print('.', end='', flush=True) messages = groupme.get_messages(before_id=before_id) print(flush=True) self.last_message = new_last_message with open(LAST_MESSAGE_FILE, "wb") as f: pickle.dump(self.last_message, f)
def group(groupID): gm = GroupMe(api_token=os.environ["GROUPME_ACCESS_TOKEN"]) group = gm.get_group_info(groupID) members = group["members"] members.sort(key=lambda x: x["name"]) messages = gm.get_messages(groupID, limit=25) return render_template("group.html", group=group, messages=messages, members=members)