class HerokuBot: def __init__(self, tempo_de_loop=60, tempo_entre_posts=10): self.tempo_entre_posts = tempo_entre_posts self.ign = Igninterage('https://www.ignboards.com/') self.gist = GistMan(GIST_TOKEN) self.ign.set_cookie(json.loads(FORUM_COOKIE)) while True: print('rodando...') self.reage_no_post_de_quem_te_mencionou() sleep(tempo_de_loop) def procura_mention(self): html = self.ign.interact_session.get('https://www.ignboards.com/account/alerts').text tree = parser.fromstring(html) alerts = tree.find_class('contentRow-main contentRow-main--close') mention_uris = [] for alert in alerts: msg_text = alert.xpath('text()')[1] if ('mentioned' or 'mencionou') in msg_text: mention_uris.append(alert.xpath('a/@href')[1]) return mention_uris def reage_no_post_de_quem_te_mencionou(self): mention_list = self.procura_mention() for item in reversed(mention_list): post_id = item.split('/')[2] ultimo_respondido = self.gist.read_gist(FILE_ID)['files']['conf.data']['content'] if int(post_id) > int(ultimo_respondido): print(f'Reagi ao post!: {post_id}') self.ign.react('1', post_id) self.gist.update_gist(FILE_ID, 'conf.data', post_id) sleep(self.tempo_entre_posts)
def __init__(self, cache_session_file, cache_file, tempo_de_loop=60): self.ign = Igninterage(self._url, cache_session_file) self.ign.ign_login() self.cache_file = cache_file while True: print('rodando...') self.responde() time.sleep(tempo_de_loop)
def __init__(self, tempo_de_loop=60, tempo_entre_posts=10): self.tempo_entre_posts = tempo_entre_posts self.ign = Igninterage('https://www.ignboards.com/') self.gist = GistMan(GIST_TOKEN) self.ign.set_cookie(json.loads(FORUM_COOKIE)) while True: print('rodando...') self.reage_no_post_de_quem_te_mencionou() sleep(tempo_de_loop)
def __init__(self, cache_session_file, cache_file, tempo_de_loop=60): self.ign = Igninterage('https://www.ignboards.com/', cache_session_file) self.ign.ign_login() self.cache_file = cache_file while True: print('rodando...') self.reage_no_post_de_quem_te_mencionou() sleep(tempo_de_loop)
class Bot2: def __init__(self, cache_session_file, cache_file, tempo_de_loop=60): self.ign = Igninterage('https://www.ignboards.com/', cache_session_file) self.ign.ign_login() self.cache_file = cache_file while True: print('rodando...') self.reage_no_post_de_quem_te_mencionou() sleep(tempo_de_loop) def procura_mention(self): html = self.ign.interact_session.get( 'https://www.ignboards.com/account/alerts').text tree = parser.fromstring(html) alerts = tree.find_class('contentRow-main contentRow-main--close') mention_uris = [] for alert in alerts: msg_text = alert.xpath('text()')[1] if ('mentioned' or 'mencionou') in msg_text: mention_uris.append(alert.xpath('a/@href')[1]) return mention_uris def ultimo_respondido_cache(self): try: return load_cache_file(self.cache_file) except FileNotFoundError: return 0 def reage_no_post_de_quem_te_mencionou(self): mention_list = self.procura_mention() for item in reversed(mention_list): int_post_id = int(item.split('/')[2]) ultimo_respondido = self.ultimo_respondido_cache() if int_post_id > ultimo_respondido: print(f'Reagi ao post!: {int_post_id}') self.ign.react('1', str(int_post_id)) save_cache_file(int_post_id, self.cache_file)
def imgflood(): ign = Igninterage('https://www.ignboards.com/') ign.ign_login() while True: try: g = gur() if g: ign.comentar(f'[img]{g}[/img]', TOPICO) else: print('erro ao recuperar imagem, continuando...') except Exception as err1: print(f'Erro, ih rapaz: {err1}. Tentando novamente...') sleep(TEMPO)
class Bot3: _url = 'https://www.ignboards.com/' def __init__(self, cache_session_file, cache_file, tempo_de_loop=60): self.ign = Igninterage(self._url, cache_session_file) self.ign.ign_login() self.cache_file = cache_file while True: print('rodando...') self.responde() time.sleep(tempo_de_loop) def get_mention(self): html = self.ign.interact_session.get(self._url + 'account/alerts').content tree = parser.fromstring(html) alerts = tree.find_class('contentRow-main contentRow-main--close') mention_uris = [] for alert in alerts: msg_text = alert.xpath('text()')[1] if 'men' in msg_text: mention_uris.append(alert.xpath('a/@href')[1]) return mention_uris def ultimo_respondido_cache(self): try: return load_cache_file(self.cache_file) except FileNotFoundError: return 0 def get_quem_te_mencionou(self): responder_list = [] mention_list = self.get_mention() for item in reversed(mention_list): int_post_id = int(item.split('/')[-2]) ultimo_respondido = self.ultimo_respondido_cache() if int_post_id > ultimo_respondido: save_cache_file(int_post_id, self.cache_file) responder_list.append(item) return responder_list def procura_posts(self): mentions = self.get_quem_te_mencionou() post_mentions = [] for mention in mentions: mention = 'posts' + mention.split('posts')[1] html = self.ign.interact_session.get(self._url + mention).content tree = parser.fromstring(html) post_id = mention.split('/')[-2] xpath_user = f'//*[@id="js-post-{post_id}"]' xpath_text = f'{xpath_user}/div/div[2]/div/div[1]/div/article/div[1]' my_username = tree.find_class( 'p-navgroup-linkText')[0].text_content() thread = tree.find_class('block-container lbContainer' )[0].attrib['data-lb-id'].split('-')[1] user = tree.xpath(xpath_user)[0].attrib['data-author'] text = tree.xpath(xpath_text)[0].text_content().replace( f'@{my_username}', '').strip().lower() post_mentions.append([thread, post_id, user, text]) return post_mentions def responde(self): perguntas = self.procura_posts() for pergunta_list in perguntas: thread, post, user, pergunta = pergunta_list for cada in estrutura_demo['palavras_chave']: modo = cada['modo'] cada_chave = cada['chave'] respostas = cada['resposta'] if modo == 'random': check = any(item in pergunta for item in cada_chave) if check: try: full_resp = f'[QUOTE="{user}, post: {post}"]{pergunta}[/QUOTE]{choice(respostas)}' self.ign.comentar(full_resp, thread) time.sleep(20) except (ConnectionError, ex.LoginError, ex.NotXenforoPage) as err: print(err) print('tentar novamente ?') if modo == 'action': check = any(item in pergunta for item in cada_chave) if check: resp = actions(respostas) if resp: full_resp = f'[QUOTE="{user}, post: {post}"]{pergunta}[/QUOTE]{resp}' try: self.ign.comentar(full_resp, thread) time.sleep(20) except (ConnectionError, ex.LoginError, ex.NotXenforoPage) as err2: print(err2) print('tentar novamente ?') else: continue
"chave": ["ze sims", "zelão", "jose sims", "jose"], "resposta": ["abre o boção", "potchi leva modera"] }, { "modo": "todas", "excluir": [], "chave": ["duro", "golpe"], "resposta": ["nada mais pode ser feito", "RIP"] }, { "modo": "todas", "excluir": [], "chave": ["avaliem"], "resposta": ["penta", "mono", "avaliando com estrelas"] }] } ign = Igninterage('https://www.ignboards.com/', 'cache.session') session = requests.Session() ign.ign_login() def bot(dicionario): req = session.get('https://www.ignboards.com/forums/vale-tudo.80331/') html = req.text tree = parser.fromstring(html) threads = tree.find_class('structItem-title') for thread in threads: palavras = thread.values()[1][9:-11].split('-') thread_id = thread.values()[1][-10:-1]
def printa_seus_cookies_de_login(): ign = Igninterage('https://www.ignboards.com/') ign.ign_login() print(json.dumps(ign.interact_session.cookies.get_dict()))
from time import sleep from igninterage import Igninterage from lxml.html import fromstring MENSAGEM = '[MEDIA=twitter]1363989931736072192[/MEDIA]' # A mensagem da MP TOPICO = 'Viih tube pagando peitinho' # titulo do topico TEMPO = 30 COD_REC_CONF = 'cod_rec.conf' URL = 'https://www.ignboards.com/' ign = Igninterage(URL, navegador='chrome') ign.ign_login() def load_conf(file): try: with open(file) as f: return f.read() except FileNotFoundError: return '0' def save_conf(file, data): with open(file, 'w') as f: f.write(data) def topico_data(id_post): html = ign.interact_session.get(f'{URL}/posts/{id_post}/').content tree = fromstring(html) xpath_user = f'//*[@id="js-post-{id_post}"]'