<commit_before>#!/usr/bin/env python3

import logging
import tweepy
import re
import requests
import report
from time import time
from bot import Bot


logger = logging.getLogger(__name__)


class TwitterBot(Bot):
    def get_api(self, user):
        keys = user.get_api_keys()
        auth = tweepy.OAuthHandler(consumer_key=keys[0],
                                   consumer_secret=keys[1])
        auth.set_access_token(keys[2],  # access_token_key
                              keys[3])  # access_token_secret
        return tweepy.API(auth, wait_on_rate_limit=True)

    def crawl(self, user):
        """
        crawls all Tweets which mention the bot from the twitter rest API.

        :return: reports: (list of report.Report objects)
        """
        reports = []
        try:
            if user.get_last_twitter_request() + 60 > time():
                return reports
        except TypeError:
            user.set_last_twitter_request(time())
        try:
            api = self.get_api(user)
        except IndexError:
            return reports  # no twitter account for this user.
        last_dm = user.get_seen_dm()
        try:
            if last_dm is None:<commit_msg>fixing bug; twitterDM object wasn't created<commit_after>#!/usr/bin/env python3

import logging
import tweepy
import re
import requests
import report
from time import time
from bot import Bot


logger = logging.getLogger(__name__)


class TwitterDMListener(Bot):
    def get_api(self, user):
        keys = user.get_api_keys()
        auth = tweepy.OAuthHandler(consumer_key=keys[0],
                                   consumer_secret=keys[1])
        auth.set_access_token(keys[2],  # access_token_key
                              keys[3])  # access_token_secret
        return tweepy.API(auth, wait_on_rate_limit=True)

    def crawl(self, user):
        """
        crawls all Tweets which mention the bot from the twitter rest API.

        :return: reports: (list of report.Report objects)
        """
        reports = []
        try:
            if user.get_last_twitter_request() + 60 > time():
                return reports
        except TypeError:
            user.set_last_twitter_request(time())
        try:
            api = self.get_api(user)
        except IndexError:
            return reports  # no twitter account for this user.
        last_dm = user.get_seen_dm()
        try:
            if last_dm is None:
{'fraction_non_alphanumeric': 0.08151502675998354, 'fraction_numerical': 0.005763688760806916, 'mean_word_length': 2.029925187032419, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2067267', 'n_tokens_mistral': 709, 'n_tokens_neox': 682, 'n_words': 186}