def getMetadata(): date_str = request.args.get('date') if not date_str: return "missing date", 400 date = date_helpers.parse_date_str(date_str) entries = models.entries.find_for_user_and_month(g.user["_id"], date) entry_metadata_arr = [entry["metadata"] for entry in entries] summary = TasksParser.summerize(entry_metadata_arr, date) return jsonify(metadata=entry_metadata_arr, summary=summary)
def perform_update(date_str, date, action, params): metadata = models.entries.find_one_for_user_and_date(g.user["_id"], date) parser = TasksParser(date_str, "") if metadata: parser.from_dict(metadata["metadata"]) if action == 'add_line': parser.add_line(params["line"], params["is_after_midnight"]) elif action == 'edit_line': parser.edit_line(params["prev_line"], params["new_line"], params["is_after_midnight"]) content = parser.to_tasks_file() entry_metadata = parser.to_dict() # update dropbox dropbox = DropboxApi() filename = date_str + ".md" file_metadata = dropbox.update_file(g.user["dropbox_access_token"], "/journal/" + filename, content) return models.entries.create_or_update_entry(g.user["_id"], filename, date, entry_metadata, file_metadata)
def perform_update(date_str, date, action, params): metadata = models.entries.find_one_for_user_and_date(g.user["_id"], date) parser = TasksParser(date_str, "") if metadata: parser.from_dict(metadata["metadata"]) if action == "add_line": parser.add_line(params["line"], params["is_after_midnight"]) elif action == "edit_line": parser.edit_line(params["prev_line"], params["new_line"], params["is_after_midnight"]) content = parser.to_tasks_file() entry_metadata = parser.to_dict() # update dropbox dropbox = DropboxApi() filename = date_str + ".md" file_metadata = dropbox.update_file(g.user["dropbox_access_token"], "/journal/" + filename, content) return models.entries.create_or_update_entry(g.user["_id"], filename, date, entry_metadata, file_metadata)
def getTags(): date_str = request.args.get('date') tags = [] if date_str is not None: date = date_helpers.parse_date_str(date_str) entry = models.entries.find_one_for_user_and_date(g.user["_id"], date) if entry is not None: summary = TasksParser.summerize([entry['metadata']], date) tags.extend([{"type": "tag", "tag": tag} for tag in summary["tags"]]) tags.extend([{"type": "person", "tag": tag} for tag in summary["people"]]) tags.extend([{"type": "location", "tag": tag} for tag in summary["locations"]]) else: tags = models.tags.get_all_tags(g.user["_id"]) return jsonify(tags=tags)
def updateJournal(): date_str = request.json['date'] content = request.json['text'] # update dropbox dropbox = DropboxApi() filename = date_str + ".md" file_metadata = dropbox.update_file(g.user["dropbox_access_token"], "/journal/" + filename, content) # update metadata date = date_helpers.parse_date_str(date_str) entry_metadata = {} if len(content) > 0: entry_metadata = TasksParser(date_str, content).to_dict() models.entries.create_or_update_entry(g.user["_id"], filename, date, entry_metadata, file_metadata) return jsonify({"success": True, **file_metadata})
def process_user(dropbox_user_id): # OAuth token for the user user = models.user.find_user_by_dropbox_id(str(dropbox_user_id)) if not user: app.logger.error("User {0} was not found".format(dropbox_user_id)) return cursor = None if "hook_cursor" in user: cursor = user["hook_cursor"] app.logger.info("Processing update for user {0}".format(user["email"])) dropbox = DropboxApi() results, cursor = dropbox.get_files_in_folder("/journal", user["dropbox_access_token"], cursor) for result in results: app.logger.info("processing changed file {0}, with name: {1}".format( result["path_lower"], result["name"])) response = dropbox.get_file_content(user["dropbox_access_token"], result["path_lower"]) content = response["content"] date_str = result["name"][:-3] filename = result["name"] try: date = date_helpers.parse_date_str(date_str) except ValueError: continue entry_metadata = TasksParser(date_str, content).to_dict() models.entries.create_or_update_entry(user["_id"], filename, date, entry_metadata, dict_without(response, "content")) app.logger.info("Finished processing update for user {0}".format( user["email"])) models.user.save_hook_cursor(user["_id"], cursor)
def getTags(): date_str = request.args.get('date') tags = [] if date_str is not None: date = date_helpers.parse_date_str(date_str) entry = models.entries.find_one_for_user_and_date(g.user["_id"], date) if entry is not None: summary = TasksParser.summerize([entry['metadata']], date) tags.extend([{ "type": "tag", "tag": tag } for tag in summary["tags"]]) tags.extend([{ "type": "person", "tag": tag } for tag in summary["people"]]) tags.extend([{ "type": "location", "tag": tag } for tag in summary["locations"]]) else: tags = models.tags.get_all_tags(g.user["_id"]) return jsonify(tags=tags)