Beispiel #1
0
def direct_messages(config):
    """
    Send direct messages to new followers
    :param config:
    :return:
    """
    # Connection to Twitter
    twitter_connector = TweetBotConnector(config)

    # Friends
    friends_manager = FriendsManager()

    # DB connector
    mysql_connector = DBConnector()

    # Direct message
    msg = config.direct_message

    # Get friend to contact
    for friend in friends_manager.get_uncontacted_friends():
        # Send direct message
        twitter_connector.send_direct_message(
            text=msg, screen_name=friend.friend_screen_name)

        # Set as contacted
        friend.friend_contacted = True

        # Commit
        mysql_connector.get_session().commit()

        # Wait
        logging.getLogger(pystr.LOGGER).info(pystr.INFO_TWITTER_WAIT)
        time.sleep(60)
Beispiel #2
0
 def get_tokens(model, c=None):
     """
     Get token probs for a model
     :param model: Model's name
     :param c: Class
     :return:
     """
     if c is None:
         return DBConnector().get_session().query(ModelToken).filter(
             ModelToken.token_model == model).all()
     else:
         return DBConnector().get_session().query(ModelToken).join(
             ModelToken.token_model).filter(
                 ModelToken.token_class == c).all()
Beispiel #3
0
 def exists(name):
     """
     Does a model exists?
     :param name: Model's name
     :return: True or False
     """
     return DBConnector().get_session().query(Model).filter(
         Model.model_name == name).count() > 0
Beispiel #4
0
 def get_by_name(name):
     """
     Get a model by its name
     :param name: Model's name
     :return: Model DB object
     """
     return DBConnector().get_session().query(Model).filter(
         Model.model_name == name).one()
Beispiel #5
0
 def exists(user_id):
     """
     Exists
     :param user_id:
     :return:
     """
     return DBConnector().get_session().query(User).filter(
         user_id == user_id).count() > 0
Beispiel #6
0
 def get(user_id):
     """
     Get user
     :param user_id:
     :return:
     """
     return DBConnector().get_session().query(User).filter(
         user_id == user_id).all()[0]
Beispiel #7
0
 def exists(week_day, hour):
     """
     Impact statistics exists?
     :param week_day:
     :param hour:
     :return:
     """
     return DBConnector().get_session().query(ImpactStatistic).filter(
         and_(ImpactStatistic.impact_statistic_week_day == week_day,
              ImpactStatistic.impact_statistic_hour == hour)).count() > 0
Beispiel #8
0
 def update(week_day, hour, count):
     """
     Update
     :param week_day:
     :param hour:
     :param count:
     :return:
     """
     DBConnector().get_session().query(ImpactStatistic).filter(
         and_(ImpactStatistic.impact_statistic_week_day == week_day,
              ImpactStatistic.impact_statistic_hour == hour)).update(
                  {"impact_statistic_count": count})
Beispiel #9
0
    instagram = None

    # Need config and connect?
    if args.command != "tools" or not args.create_config:
        # Load configuration file
        try:
            config = BotConfig.load(args.config)
        except MissingRequiredField as e:
            sys.stderr.write(pystr.ERROR_PARSING_CONFIG_FILE.format(e))
            exit()
        # end try

        # Connection to MySQL
        dbc = config.database
        mysql_connector = DBConnector(host=dbc["host"],
                                      username=dbc["username"],
                                      password=dbc["password"],
                                      db_name=dbc["database"])

        # Login instagram
        instagram_connector = InstagramConnector(config)

        # Friends manager
        friends_manager = friends.FriendsManager(instagram)

        # Action scheduler
        action_scheduler = ActionScheduler(config=config)
    # end if

    # Different possible command
    if args.command == "medias":
        add_medias(args.add, args.caption, action_scheduler)
Beispiel #10
0
    # Learning
    learning_parser = command_subparser.add_parser("learning")
    learning_parser.add_argument("--task", type=str, help="Task to learn (post, like, comment, follow)")
    learning_parser.add_argument("--gui", action='store_true', help="Show graphical user interface", default=False)
    learning_parser.add_argument("--output", type=str, help="Output file where to store the dataset", required=True)
    add_default_arguments(learning_parser)

    # Parse
    args = parser.parse_args()

    # Logging
    logging.basicConfig(level=20, format='%(asctime)s :: %(levelname)s :: %(message)s')

    # Connection to MySQL
    mysql_connector = DBConnector(host="localhost", username="******", password="******", db_name="nilsbot")

    # Test command
    # Update statistics
    if args.command == "learning":
        # Which task
        if args.task == "post":
            window = ImageClassificationWindow()
            window.show()
        # end if
    # Find tweets

    instagram = Instagram(user_id=2926312088, username="******", password="******")

    instagram.login()