from __future__ import absolute_import from flask import current_app from windowbox.application import app from windowbox.models.attachment import Attachment with app.app_context(): bads = Attachment.query.filter( Attachment.geo_latitude.isnot(None), Attachment.geo_longitude.isnot(None), Attachment.geo_address.is_(None)).all() for bad in bads: print 'Fixing geo address on attachment #{}'.format(bad.id) bad.geo_address = Attachment._load_address_data( bad.geo_latitude, bad.geo_longitude, current_app.config['GOOGLE_API_KEY']) bad.save(commit=True)
for message in sorted(messages): app.logger.info("Message ID %s, sent on %s", message.message_id, message.created_utc) real_name, email = message.sender if email not in app.config["IMAP_ALLOWED_FROM"]: app.logger.error("Skipping; %s is not a permitted sender", email) continue attach_data = message.get_attachment_data(valid_types) if not attach_data: app.logger.error("Skipping; no usable attachment") continue post_kwargs = { "created_utc": message.created_utc, "message": message.message_body, "user_agent": message.user_agent, } app.logger.debug("Inserting post data: %s", repr(post_kwargs)) post = Post(**post_kwargs).save(commit=True) app.logger.debug("Inserting attachment: <%d bytes>", len(attach_data)) attachment = Attachment(post_id=post.id) attachment.set_data(attach_data) attachment.save(commit=True) app.logger.info("Created post #%d, attachment #%d", post.id, attachment.id) imap_manager.close() app.logger.info("Check has finished.")
from __future__ import absolute_import from windowbox.application import app from windowbox.models.attachment import Attachment with app.app_context(): bads = Attachment.query.filter( Attachment.geo_latitude.isnot(None), Attachment.geo_longitude.isnot(None), Attachment.geo_address.is_(None)).all() for bad in bads: print 'Fixing geo address on attachment #{}'.format(bad.id) bad.geo_address = Attachment._load_address_data(bad.geo_latitude, bad.geo_longitude) bad.save(commit=True)