Create a gist now

Instantly share code, notes, and snippets.

Facebookのグループ新着チェック
# -*- coding: utf-8 -*-
from selenium import webdriver
import requests
import json
import sys
argvs = sys.argv
if len(argvs) != 4:
print('Usage: python %s username password slack_webhocks_url' % argvs[0])
quit()
driver = webdriver.PhantomJS()
driver.get('https://www.facebook.com/')
# ログイン
form = driver.find_element_by_css_selector("form#login_form")
user_login = form.find_element_by_css_selector("input[name='email']")
user_login.send_keys(argvs[1])
password = form.find_element_by_css_selector("input[name='pass']")
password.send_keys(argvs[2])
form.submit()
pinnedNav = driver.find_element_by_css_selector("#groupsNav")
for elem in pinnedNav.find_elements_by_css_selector("li > a"):
data = json.loads(elem.get_attribute('data-gt'))
if int(data['count']) > 0:
requests.post(argvs[3], data=json.dumps({
'text': '%s %s' % (elem.get_attribute('title'), data['count']),
'username': 'ghost',
'icon_emoji': ':ghost:',
'link_names': 1
}))
driver.quit()
FROM centos:7
MAINTAINER shunsuke maeda <duck8823@nig.ac.jp>
# 依存ライブラリ
RUN yum update -y
RUN yum install -y gcc make wget bzip2 fontconfig openssl-devel
# Python 3.5
WORKDIR /tmp
RUN wget -q https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
RUN tar xzf Python-3.5.2.tgz
WORKDIR ./Python-3.5.2
RUN ./configure --with-threads
RUN make install
# スクリプトの依存ライブラリ
RUN python3 -m ensurepip && \
pip3 install --upgrade pip && \
pip3 install requests selenium
# PhantomJS
RUN wget -q https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 && \
tar xjf phantomjs-2.1.1-linux-x86_64.tar.bz2 && \
mv phantomjs-2.1.1-linux-x86_64 /usr/local/phantomjs
ENV PATH $PATH:/usr/local/phantomjs/bin
RUN mkdir /tmp/work
COPY check_facebook_new.py /tmp/work/
WORKDIR /tmp/work
CMD python3 check_facebook_new.py $LOGIN_USER $LOGIN_PASSWORD $SLACK_WEBHOOKS_URL
python check_facebook_new.py ユーザ名 パスワード https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXX
docker build -t check_facebook_new .
docker run --rm \
-e LOGIN_USER=ユーザ名 \
-e LOGIN_PASSWORD=パスワード \
-e SLACK_WEBHOOKS_URL=https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXX \
check_facebook_new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment