投稿
utils.py
- リンクを取得
- ×
- メール
- 他のアプリ
# -*- coding: utf-8 -*- import logging import os import random from time import sleep logger = logging.getLogger('sns.utils') _format = '%(asctime)s [%(name)s] [%(filename)s:%(lineno)s] [%(levelname)s] %(message)s' def init_loggers(): logger = logging.getLogger('sns') # type: logging.Logger level = logging.INFO if os.getenv('LOG_LEVEL'): level = logging.getLevelName(os.getenv('LOG_LEVEL')) try: logger.setLevel(level) except: logger.setLevel(logging.INFO) # Stream ch = logging.StreamHandler() ch.setFormatter(logging.Formatter(_format)) logger.addHandler(ch) def random_sleep(self, min_seconds=0.5, max_seconds=2): wait = random.random() * (max_seconds - min_seconds) + min_seconds sleep(wait)
drivers.py
- リンクを取得
- ×
- メール
- 他のアプリ
# -*- coding: utf-8 -*- import platform from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from notifier import Notifier class Driver(webdriver.Chrome): def __init__(self): options = webdriver.ChromeOptions() # TODO cloud9で動かす場合はONにする # options.add_argument('--headless') # options.add_argument('--disable-gpu') options.add_argument('--window-size=1920,1080') options.add_argument('--start-maximized') options.add_experimental_option('w3c', False) options.add_argument('--ignore-certificate-errors') options.add_argument('--ignore-ssl-errors') options.add_argument('--allow-running-insecure-content') options.add_argument('--disable-web-security') options.add_argument('--disable-desktop-notifications') options.add_argument('--disable-default-apps') opti...
main.py
- リンクを取得
- ×
- メール
- 他のアプリ
from asyncio.log import logger import logging import random import argparse from credentials import KEYWORDS from instagram import Instagram from instagram import INSTAGRAM_ID,INSTAGRAM_PASSWORD from utils import init_loggers, random_sleep if __name__ == '__main__': init_loggers() #IDとpasswordをコマンドライン引数から取得する parser = argparse.ArgumentParser() parser.add_argument('id') parser.add_argument('password') #コマンドライン引数を解析する account = parser.parse_args() #IDをmodelに送り、オブジェクトを作成する。 instagram = Instagram() INSTAGRAM_ID = account.id INSTAGRAM_PASSWORD = account.password try: #有効フォロウィーのアカウントDBからを取得 active_followee_accounts = ['kotobike_5100'] #ログイン instagram.login() #フォロー機能1 #有効フォロウィーのアカウントを取得 parent_accounts = active_followee_accounts break_flg1 = 0 j=0 #フォローした人数が15人を超えるまでフォロー処理1を繰り返す(とりあえず、こちらのEOFはなしで進める) while break_...
instagram.py
- リンクを取得
- ×
- メール
- 他のアプリ
from lib2to3.pgen2 import driver import logging from pickletools import floatnl import random from unittest import loader from selenium.webdriver.support.ui import WebDriverWait import instaloader from time import sleep from drivers import Driver #IDとpasswordを定義 INSTAGRAM_ID = ''#仮に定義しておく INSTAGRAM_PASSWORD ='' logger = logging.getLogger('sns.instagram') class Instagram(Driver): def __init__(self): super(Instagram, self).__init__() self.page = None #フィールドに値をセット #idとpasswordDBからを取得する #インスタグラムにログインを行う def login(self): try: #インスタグラムにアクセス self.get('https://www.instagram.com/accounts/login/') sleep(3) #ログインフォームを探し、入力する。 sign_box = self.find_element_by_tag_name('form') sign_box.find_element_by_name('username').send_keys(INSTAGRAM_ID) sign_box.find_element_by_name('password').send_keys(INSTAGRAM_...