示例#1
0
def facebook_parse_messages(thread_id, last_message_id, json_string):
	result = { }

	try:
		conversation = database.get_facebook_conversation(thread_id)
		if not(conversation is None):
			conversation.set_last_message_id(last_message_id)
		else:
			database.add_facebook_conversation(thread_id, last_message_id)

		messages = json.loads(json_string)

		links = []
		for message in messages:
			if 'text' in message:
				if not(':ig:' in message['text']):
					urls = utils.extract_links(message['text'])
					date = utils.parse_date(message['date'])
					title = ''

					if ':rt:' in message['text']:
						title = utils.extract_title(message['text'], urls)
					
					for i in range(len(urls)):
						if 'linkbucket.joshasch.com' not in urls[i]:
							link = database.add_link(urls[i], date)
							if len(title) > 0:
								if len(urls) > 1:
									link = database.edit_title_without_counting(link.id, title + " (" + str(i+1) + ")")
								else:
									link = database.edit_title_without_counting(link.id, title)

							link_dict = {
								"id": link.id,
								"title": link.title,
								"url": link.url,
								"domain": link.domain,
								"image_url": link.image_url,
								"embed_url": link.embed_url,
								"embed_type": link.embed_type,
								"screenshot_url": screenshots.get_screenshot(link.url),
								"timesince": utils.timesince(link.date)
							}
							links.append(link_dict)

		result = {
			'success': True,
			'thread_id': thread_id,
			'links': links
		}
	except Exception as error:
		result = {
			'success': False,
			'message': str(error)
		}

	return jsonify(result)
示例#2
0
def add_customer():
    name = request.json['name']
    dob = request.json['dob']
    dob_object = parse_date(dob)
    if not dob_object:
        return jsonify(error_response("Invalid Date"))
    new_customer = Customer(name, dob_object)
    db.session.add(new_customer)
    db.session.commit()
    return customer_schema.dump(new_customer)
示例#3
0
def update_customer(id):
    customer = Customer.query.get(id)
    if not customer:
        return jsonify(error_response("Customer doesn't exist"))
    name = request.json['name']
    dob = request.json['dob']
    dob_object = parse_date(dob)
    if not dob_object:
        return jsonify(error_response("Invalid Date"))
    updated_at = datetime.datetime.now()
    customer.name = name
    customer.dob = dob_object
    customer.updated_at = updated_at
    db.session.commit()
    return customer_schema.jsonify(customer)
示例#4
0
	def __init__(self, json_release):
		self.tag_name = json_release['tag_name']
		self.body = json_release['body']
		self.date = utils.parse_date(json_release['created_at'])
		self.url = json_release['html_url']
示例#5
0
 def __get_endpoint(self, endpoint: str) -> datetime:
     """Returns a datetime given 'start' or 'end' as the endpoint"""
     return parse_date(self.details[endpoint].get(
         "dateTime", self.details[endpoint].get("date")),
                       from_tz=self.timezone(),
                       to_tz=self.timezone())
示例#6
0
 def from_events(event1, event2):
     return NGraph(event1['text'] + event2['text'],
                   util.parse_date(event1['time']),
                   util.parse_date(event2['time']), event1['index'],
                   event2['index'])
示例#7
0
 def append_event(self, event):
     self.name += event['text']
     self.n += len(event['text'])
     self.end_time = util.parse_date(event['time'])
     self.end_index = util.parse_index(event['index'])
     self.recalculate_time_taken()
示例#8
0
 async def convert(self, ctx: commands.Context, arg: str):
     if (datetime_obj := parse_date(arg)) is not None:
         return int((datetime_obj - datetime.utcnow()).total_seconds())
示例#9
0
 async def transform(cls, interaction: discord.Interaction,
                     value: str) -> datetime:
     if (datetime_obj := parse_date(value)) is not None:
         return datetime_obj