if 'attachments' in attachment: file_type = 'attachment' url = attachment['attachments'][0].get('from_url') else: file_type = 'file_share' if attachment.get( 'file' ): # Apparently, there's an edge case with uploaded null files. /shrug url = attachment['file']['url_private'] if url and re.search(pattern, url): results.append( (msg['id'], url, msg['channel'], msg['channel_date'], attachment['user'], file_type)) return results if __name__ == "__main__": from models import Slack import csv query = (Slack.select()) rows = SlackAttachmentCheck.iterate_through_json_obj(query) pattern = "docs\.google\.com" results = SlackAttachmentCheck.check_urls_in_attachments(pattern, rows) with open('results.csv', 'w') as csvfile: slackwriter = csv.writer(csvfile) for res in results: slackwriter.writerow(res)
def get_data(): return (Slack.select().limit(1000))