├── .ignore ├── .idea ├── .name ├── dictionaries │ └── chenyueling.xml ├── scopes │ └── scope_settings.xml ├── encodings.xml ├── vcs.xml ├── misc.xml ├── inspectionProfiles │ ├── profiles_settings.xml │ └── Project_Default.xml ├── modules.xml ├── ding-factory.iml └── codeStyleSettings.xml ├── start.py ├── model ├── __init__.py ├── __init__.pyc ├── message.pyc └── message.py ├── test ├── __init__.py ├── testRQ.pyc ├── __init__.pyc ├── testScheduler.py ├── testRQ.py ├── testjson.py └── testQueue.py ├── utils ├── __init__.py ├── Queue.pyc ├── config.pyc ├── __init__.pyc ├── push_task.pyc ├── timeHelper.pyc ├── redisFactory.pyc ├── Queue.py ├── redisFactory.py ├── config.py ├── timeHelper.py └── push_task.py ├── plugin ├── __init__.py ├── lofter │ ├── __init__.py │ ├── html.html │ ├── __init__.pyc │ ├── lofterTask.pyc │ ├── lofterUtils.pyc │ ├── lofterTask.py │ ├── net.py │ └── lofterUtils.py ├── toutiao │ ├── __init__.py │ ├── __init__.pyc │ ├── toutiaoTask.pyc │ ├── toutiaoUtils.pyc │ ├── toutiaoUtils.py │ └── toutiaoTask.py └── __init__.pyc ├── service ├── __init__.py ├── __init__.pyc ├── serverService.pyc └── serverService.py ├── README.md ├── worker.py ├── ding-factory.py └── html.html /.ignore: -------------------------------------------------------------------------------- 1 | ./idea 2 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | ding-factory -------------------------------------------------------------------------------- /start.py: -------------------------------------------------------------------------------- 1 | __author__ = 'chenyueling' 2 | -------------------------------------------------------------------------------- /model/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'chenyueling' 2 | -------------------------------------------------------------------------------- /test/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'chenyueling' 2 | -------------------------------------------------------------------------------- /utils/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'chenyueling' 2 | -------------------------------------------------------------------------------- /plugin/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'chenyueling' 2 | -------------------------------------------------------------------------------- /service/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'chenyueling' 2 | -------------------------------------------------------------------------------- /plugin/lofter/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'chenyueling' 2 | -------------------------------------------------------------------------------- /plugin/toutiao/__init__.py: -------------------------------------------------------------------------------- 1 | __author__ = 'chenyueling' 2 | -------------------------------------------------------------------------------- /test/testRQ.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenyueling/python_lofter/HEAD/test/testRQ.pyc -------------------------------------------------------------------------------- /utils/Queue.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenyueling/python_lofter/HEAD/utils/Queue.pyc -------------------------------------------------------------------------------- /utils/config.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenyueling/python_lofter/HEAD/utils/config.pyc -------------------------------------------------------------------------------- /model/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenyueling/python_lofter/HEAD/model/__init__.pyc -------------------------------------------------------------------------------- /model/message.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenyueling/python_lofter/HEAD/model/message.pyc -------------------------------------------------------------------------------- /test/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenyueling/python_lofter/HEAD/test/__init__.pyc -------------------------------------------------------------------------------- /utils/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenyueling/python_lofter/HEAD/utils/__init__.pyc -------------------------------------------------------------------------------- /plugin/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenyueling/python_lofter/HEAD/plugin/__init__.pyc -------------------------------------------------------------------------------- /service/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenyueling/python_lofter/HEAD/service/__init__.pyc -------------------------------------------------------------------------------- /utils/push_task.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenyueling/python_lofter/HEAD/utils/push_task.pyc -------------------------------------------------------------------------------- /utils/timeHelper.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenyueling/python_lofter/HEAD/utils/timeHelper.pyc -------------------------------------------------------------------------------- /plugin/lofter/html.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenyueling/python_lofter/HEAD/plugin/lofter/html.html -------------------------------------------------------------------------------- /utils/redisFactory.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenyueling/python_lofter/HEAD/utils/redisFactory.pyc -------------------------------------------------------------------------------- /plugin/lofter/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenyueling/python_lofter/HEAD/plugin/lofter/__init__.pyc -------------------------------------------------------------------------------- /service/serverService.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenyueling/python_lofter/HEAD/service/serverService.pyc -------------------------------------------------------------------------------- /plugin/lofter/lofterTask.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenyueling/python_lofter/HEAD/plugin/lofter/lofterTask.pyc -------------------------------------------------------------------------------- /plugin/toutiao/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenyueling/python_lofter/HEAD/plugin/toutiao/__init__.pyc -------------------------------------------------------------------------------- /plugin/lofter/lofterUtils.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenyueling/python_lofter/HEAD/plugin/lofter/lofterUtils.pyc -------------------------------------------------------------------------------- /plugin/toutiao/toutiaoTask.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenyueling/python_lofter/HEAD/plugin/toutiao/toutiaoTask.pyc -------------------------------------------------------------------------------- /plugin/toutiao/toutiaoUtils.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenyueling/python_lofter/HEAD/plugin/toutiao/toutiaoUtils.pyc -------------------------------------------------------------------------------- /.idea/dictionaries/chenyueling.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/scopes/scope_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /utils/Queue.py: -------------------------------------------------------------------------------- 1 | __author__ = 'chenyueling' 2 | 3 | 4 | from rq import Queue 5 | 6 | from redisFactory import getRedis 7 | 8 | r = getRedis() 9 | Q = Queue(connection=r) 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | python_lofter 2 | ============= 3 | 4 | > if you want test lofter , http://www.lofter.com 5 | > you should fill package utils.config.py 6 | > attribute USERNAME , PASSWORD by you lofter account http://www.lofter.com 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /utils/redisFactory.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | __author__ = 'chenyueling' 4 | 5 | import redis 6 | 7 | 8 | import utils.config 9 | 10 | pool = redis.ConnectionPool(host=utils.config.REDIS_HOST, port=utils.config.REDIS_PORT , db=0) 11 | 12 | 13 | 14 | 15 | def getRedis(): 16 | print pool 17 | return redis.Redis(connection_pool=pool) 18 | -------------------------------------------------------------------------------- /test/testScheduler.py: -------------------------------------------------------------------------------- 1 | __author__ = 'chenyueling' 2 | 3 | import time 4 | from apscheduler.scheduler import Scheduler 5 | import plugin.lofter.lofterTask 6 | schedudler = Scheduler(daemonic = False) 7 | 8 | 9 | @schedudler.cron_schedule(second='*', day_of_week='0-5', hour='8-10,13-15') 10 | def quote_send_sh_job(): 11 | print 'a simple cron job start at' , time.datetime.now() 12 | 13 | schedudler.add_interval_job(plugin.lofter.lofterTask.task(),seconds=2) 14 | 15 | 16 | 17 | schedudler.start() 18 | -------------------------------------------------------------------------------- /model/message.py: -------------------------------------------------------------------------------- 1 | __author__ = 'chenyueling' 2 | 3 | import json 4 | 5 | 6 | class ArticleMessage(object): 7 | def __init__(self, link, title, summary=None, audience='all'): 8 | self.article = { 9 | 'title': title, 10 | 'link': link, 11 | } 12 | 13 | if summary != None: 14 | self.article['summary'] = summary 15 | self.audience = audience 16 | self.type = 'ARTICLE' 17 | 18 | def get_json(self): 19 | return json.dumps(self.__dict__) 20 | 21 | 22 | #Test 23 | print ArticleMessage('link','title','summary').get_json() -------------------------------------------------------------------------------- /utils/config.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | 4 | # when we create new service should add service name to ALLOW_SERVICE 5 | # split by ',' 6 | 7 | ALLOW_SERVICE = 'lofter,toutiao_news,toutiao_gallery' 8 | 9 | 10 | ##lofter account 11 | 12 | USERNAME = 'chen_yueling@163.com' 13 | PASSWORD = 'xxxxxxxx' 14 | 15 | #DING_SERVER_HOST = 'http://127.0.0.1:10015' 16 | 17 | DING_SERVER_HOST = 'http://demo.91dd.cc:10015' 18 | 19 | NOTFY_URL = DING_SERVER_HOST + '/v1/service/{service_id}/{c_id}/push' 20 | 21 | 22 | 23 | ## redis 24 | 25 | #REDIS_HOST = '127.0.0.1' 26 | REDIS_HOST = 'demo.91dd.cc' 27 | REDIS_PORT = '20016' 28 | -------------------------------------------------------------------------------- /test/testRQ.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | __author__ = 'chenyueling' 4 | 5 | 6 | from apscheduler.scheduler import Scheduler 7 | import utils.Queue 8 | import utils.redisFactory 9 | 10 | def task(): 11 | print 'xxx' 12 | Q = utils.Queue.Q 13 | job = Q.enqueue('test.testRQ.test') 14 | print job.result 15 | time.sleep(2) 16 | 17 | print job.result 18 | def test(): 19 | r = utils.redisFactory.getRedis() 20 | #print x 21 | r.set('fuck','123456') 22 | return 'chenyueling' 23 | 24 | schedudler = Scheduler(daemonic=False) 25 | 26 | 27 | 28 | schedudler.add_interval_job(func=task,seconds=5) 29 | 30 | 31 | schedudler.start() -------------------------------------------------------------------------------- /.idea/ding-factory.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /worker.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | import logging 4 | 5 | __author__ = 'chenyueling' 6 | import os 7 | import redis 8 | from rq import Worker, Queue, Connection 9 | import traceback 10 | import utils.config 11 | 12 | listen = ['high', 'default', 'low'] 13 | 14 | redis_url = os.getenv('REDISTOGO_URL', 'redis://localhost:%s' % (utils.config.REDIS_PORT)) 15 | conn = redis.from_url(redis_url) 16 | # conn = redisFactory.getRedis() 17 | if __name__ == '__main__': 18 | with Connection(conn): 19 | try: 20 | worker = Worker(map(Queue, listen)) 21 | worker.work() 22 | except Exception, e: 23 | logging.error(e) 24 | print traceback.format_exc() 25 | -------------------------------------------------------------------------------- /utils/timeHelper.py: -------------------------------------------------------------------------------- 1 | __author__ = 'chenyueling' 2 | 3 | import time 4 | import datetime 5 | 6 | #setting time area ,in this time area return true else return flase 7 | def time_area(start_h=0, start_m=0, start_sec=0, end_h=0, end_m=0, end_sec=0): 8 | ltime = time.localtime() 9 | start_time = datetime.datetime(ltime.tm_year, ltime.tm_mon, ltime.tm_mday, start_h, start_m, start_sec) 10 | endTime = datetime.datetime(ltime.tm_year, ltime.tm_mon, ltime.tm_mday, end_h, end_m, end_sec) 11 | 12 | start_time_stamp = time.mktime(start_time.timetuple()) 13 | end_time_stamp = time.mktime(endTime.timetuple()) 14 | currentTime = time.time() 15 | if currentTime > start_time_stamp and currentTime < end_time_stamp: 16 | return True 17 | else: 18 | return False 19 | 20 | print time_area(19, 44, 50, 20, 15, 0) -------------------------------------------------------------------------------- /test/testjson.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | __author__ = 'chenyueling' 4 | 5 | 6 | import json 7 | import urllib2 8 | 9 | class Person(object): 10 | def __init__(self,name,age,fuck): 11 | self.name = name 12 | self.age = age 13 | self.fuck = fuck 14 | self.list = [{'1':'1'},{'2':'2'},{'3':{'xxx':'xxx'},'4':{'a':'v'}}] 15 | def __repr__(self): 16 | return 'Person Object name : %s , age : %d' % (self.name,self.age) 17 | 18 | fuck = {'xxxxx':'1','xxxxxx':'2'} 19 | p = Person('Peter',22,fuck) 20 | 21 | 22 | 23 | #这个是打印对象的值 24 | #print p.__dict__ 25 | d = {'p':p.__dict__} 26 | d.update(p.__dict__) 27 | 28 | resp = urllib2.urlopen('https://gist.githubusercontent.com/chenyueling/3d17043439a82e31e33f/raw/302703975c1a09243b0094306dfd9377f9f9420e/ACTION_SERVICE_CREATE.json') 29 | 30 | jsonStr = resp.read() 31 | 32 | print jsonStr 33 | #dir 是打印出对象的属性 34 | print dir(p) 35 | 36 | #格式化对象为json 字符串的时候 indent 可以将jsonString 格式化输出 indent 后面的参数是带 37 | jsonstr = json.dumps(d,indent=4) 38 | 39 | print {'indent':4} 40 | print type(jsonstr) 41 | print type({'indent':4}) 42 | print jsonstr 43 | 44 | # json.loads(jsonStr) 这个是将json 字符串作为 45 | #另一个比较有用的dumps参数是skipkeys,默认为False。 dumps方法存储dict对象时,key必须是str类型,如果出现了其他类型的话,那么会产生TypeError异常,如果开启该参数,设为True的话,则会比较优雅的过度。 46 | print json.loads(jsonStr) 47 | 48 | 49 | 50 | print d 51 | -------------------------------------------------------------------------------- /.idea/codeStyleSettings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /utils/push_task.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | 4 | import urllib2 5 | import base64 6 | 7 | __author__ = 'chenyueling' 8 | 9 | import utils.config 10 | import json 11 | import time 12 | 13 | 14 | def push_article(postData, sid, cid, api_secret): 15 | posturl = utils.config.NOTFY_URL.replace('{service_id}', sid).replace('{c_id}', cid) 16 | print posturl 17 | # 秘钥 18 | auth = base64.encodestring(sid + ":" + api_secret).replace("\n", '') 19 | print auth 20 | headers = { 21 | 'Authorization': 'Basic %s' % auth, 22 | 'Content-Type': 'application/json', 23 | 'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 24 | 'Accept-Encoding':'gzip,deflate', 25 | 'Accept-Language':'zh-CN,zh;q=0.8,en;q=0.6', 26 | 'Cache-Control':'max-age=0', 27 | 'Accept-Charset':'utf-8', 28 | 'Connection':'keep-alive', 29 | 'Content-Type':'application/json', 30 | 'User-Agent': 'Mozilla/5.0 (X11; Linux i686 (x86_64)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36' 31 | } 32 | request = urllib2.Request(posturl, postData, headers) 33 | response = urllib2.urlopen(request) 34 | result = json.loads(response.read()) 35 | print '开始' 36 | time.sleep(175) 37 | print '结束' 38 | if result['code'] == 3000: 39 | return 'success' 40 | else: 41 | return 'fail' 42 | 43 | # auth = base64.encodestring('5944' + ':' + 'bvb6r9oxmdl3obd9ure7tz3u') 44 | #print auth 45 | 46 | print json.loads('{"code":3000,"content":"Success"}')['code'] == '3000' 47 | -------------------------------------------------------------------------------- /plugin/toutiao/toutiaoUtils.py: -------------------------------------------------------------------------------- 1 | __author__ = 'chenyueling' 2 | 3 | import urllib2 4 | import json 5 | 6 | hostUrl = 'http://www.toutiao.com' 7 | 8 | NEWS_URL = hostUrl + '/toutiao/api/article/recent/' 9 | 10 | GALLERY_URL = hostUrl + '/toutiao/api/gallery/recent/' 11 | 12 | TITLE = 'title' 13 | 14 | SUMMARY = 'summary' 15 | 16 | LINK = 'link' 17 | 18 | 19 | def get_toutiao_news(): 20 | request = urllib2.Request(NEWS_URL) 21 | 22 | response = urllib2.urlopen(request) 23 | jsonStr = response.read() 24 | 25 | news = json.loads(jsonStr) 26 | 27 | if news['message'] == 'success': 28 | data = news['data'] 29 | i = 0 30 | article = {} 31 | for item in data: 32 | print item['title'] 33 | print item['favorite_count'] 34 | print item['display_url'] 35 | if i < item['favorite_count']: 36 | i = item['favorite_count'] 37 | article[TITLE] = item['title'] 38 | # article['favorite_count'] = item['favorite_count'] 39 | article[LINK] = item['display_url'] 40 | article[SUMMARY] = item['abstract'] 41 | print article 42 | return article 43 | 44 | 45 | def get_toutiao_gallery(): 46 | request = urllib2.Request(GALLERY_URL) 47 | response = urllib2.urlopen(request) 48 | jsonStr = response.read() 49 | gallery = json.loads(jsonStr) 50 | if gallery['message'] == 'success': 51 | data = gallery['data'] 52 | for item in data: 53 | if item['desc'] != None and item['desc'] != '': 54 | article = {TITLE: item['desc'], LINK: hostUrl + item['share_url']} 55 | return article 56 | 57 | #Test 58 | #print get_toutiao_news() 59 | #print get_toutiao_gallery() -------------------------------------------------------------------------------- /test/testQueue.py: -------------------------------------------------------------------------------- 1 | __author__ = 'chenyueling' 2 | 3 | #!/usr/bin/env python 4 | # coding=utf-8 5 | ''''' 6 | @author: homer 7 | @see: ithomer.net 8 | ''' 9 | 10 | import Queue 11 | import threading 12 | import urllib, urllib2 13 | import time 14 | 15 | myqueue = Queue.Queue(maxsize=0) 16 | queue = Queue.Queue() 17 | hosts = ["http://1","http://2","http://3"] 18 | 19 | 20 | lock = threading.Lock() 21 | def printMsg(msg): 22 | global lock 23 | if lock.acquire(): 24 | print(msg) 25 | lock.release() 26 | 27 | class ThreadUrl(threading.Thread): 28 | def __init__(self, queue, htint): 29 | threading.Thread.__init__(self) 30 | self.queue = queue 31 | self.Ht = htint 32 | 33 | 34 | def run(self): 35 | print 'run run run ' + self.getName() 36 | while True: 37 | host = self.queue.get() 38 | 39 | printMsg("thread_id: " + self.getName() + ";\t htint: " + str(self.Ht) + " --- host: " + host) 40 | printMsg("qsize: %d" % self.queue.qsize()) 41 | if self.queue.empty(): 42 | printMsg("queue is empty of " + self.getName()) 43 | self.queue.task_done() 44 | 45 | def start(self): 46 | print self 47 | print 'YYYYYYYYYYYY' + self.getName() 48 | return super(ThreadUrl, self).start() 49 | 50 | 51 | def main(): 52 | # spawn a pool of threads, and pass them queue instance 53 | for i in range(5): 54 | t = ThreadUrl(queue, 'x') 55 | t.setDaemon(True) 56 | t.start() 57 | # populate queue with data 58 | #for host in hosts: 59 | for x in range(5): 60 | printMsg("xxxxxxxxxxxxxxxxxxxxxxx") 61 | queue.put(str(x)) 62 | print queue 63 | queue.join() 64 | 65 | if __name__ == "__main__": 66 | start = time.time() 67 | main() 68 | time.sleep(1) 69 | costTime = time.time() - start - 1 70 | print "Elapsed Time: %s (s)" % costTime 71 | -------------------------------------------------------------------------------- /plugin/lofter/lofterTask.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | from rq import Connection, Worker 4 | 5 | __author__ = 'chenyueling' 6 | 7 | import utils.redisFactory 8 | import lofterUtils 9 | 10 | import utils.Queue 11 | import model.message 12 | 13 | import utils.timeHelper 14 | 15 | import exceptions 16 | 17 | mark = 'lofter' 18 | 19 | 20 | def task(): 21 | redis = utils.redisFactory.getRedis() 22 | set = redis.keys(mark + '*') 23 | print set 24 | for cid in set: 25 | print cid 26 | print 'lofter in' 27 | if not utils.timeHelper.time_area(8, 0, 0, 10, 40, 0) and not utils.timeHelper.time_area(18, 0, 0, 20, 20, 0): 28 | redis.hset(cid, 'notify', 'false') 29 | print 'not satisfy' 30 | continue 31 | else: 32 | status = redis.hmget(cid, 'notify')[0] 33 | if status != None and status == 'true': 34 | print 'pushed' 35 | continue 36 | else: 37 | redis.hset(cid, 'notify', 'true') 38 | print 'push now' 39 | 40 | c_id_real = cid.split(':')[1] 41 | sid = redis.hmget(cid, 'sid')[0] 42 | tag = redis.hmget(cid, 'tag')[0] 43 | 44 | print sid 45 | # tag = '原画' 46 | print tag 47 | article = lofterUtils.get_article_byTag(tag) 48 | api_secret = redis.get('api_secret' + ':' + sid) 49 | link = article[0]['link'] 50 | title = article[0]['title'] 51 | pushData = model.message.ArticleMessage(link, title) 52 | 53 | cache_link = redis.hmget(cid, 'cache_link') 54 | print cache_link[0] 55 | if (cache_link[0] == link): 56 | continue 57 | else: 58 | redis.hmget(cid, {'cache_link': cache_link}) 59 | try: 60 | Q = utils.Queue.Q 61 | print pushData.get_json() 62 | Q.enqueue('utils.push_task.push_article', pushData.get_json(), sid, c_id_real, api_secret) 63 | except Exception, e: 64 | print e 65 | 66 | redis = utils.redisFactory.getRedis() 67 | cid = "lofter:08f6c8d9-048c-4c16-92e9-6b0c53f09737" 68 | status = redis.hmget(cid, 'notify')[0] 69 | print status 70 | if status != None and status == 'true': 71 | print 'xxx' 72 | else: 73 | print status -------------------------------------------------------------------------------- /ding-factory.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | import json 4 | import logging 5 | import traceback 6 | 7 | from flask import Flask, Response 8 | from flask import request 9 | from apscheduler.scheduler import Scheduler 10 | 11 | import service.serverService 12 | import utils.config 13 | import plugin.lofter.lofterUtils 14 | import plugin.lofter.lofterTask 15 | 16 | import plugin.toutiao.toutiaoTask 17 | import plugin.toutiao.toutiaoUtils 18 | 19 | 20 | app = Flask(__name__) 21 | 22 | 23 | @app.route('/') 24 | def hello_world(): 25 | return 'ding-factory' 26 | 27 | 28 | @app.route('/factory/py/', methods=['POST']) 29 | def process(service_name): 30 | try: 31 | print service_name 32 | jsonData = json.loads(request.data) 33 | print request.data 34 | action = jsonData["action"] 35 | isAllow = False 36 | for item in utils.config.ALLOW_SERVICE.split(','): 37 | if service_name == item: 38 | isAllow = True 39 | if service_name is None or service_name == '' or not isAllow: 40 | return 'No such Service' 41 | 42 | result = '' 43 | 44 | if action == 'ACTION_SERVICE_CREATE': 45 | result = service.serverService.action_service_create(service_name, jsonData) 46 | elif action == 'ACTION_SERVICE_UPDATE': 47 | result = service.serverService.action_service_update(service_name, jsonData) 48 | elif action == 'ACTION_CLIENT_SERVICE_CREATE': 49 | result = service.serverService.action_client_service_create(service_name, jsonData) 50 | elif action == 'ACTION_SERVICE_FOLLOWED_CHANGE': 51 | result = service.serverService.action_service_followed_change(service_name, jsonData) 52 | elif action == 'ACTION_SERVICE_DING': 53 | result = service.serverService.action_service_ding(action, jsonData) 54 | 55 | 56 | except Exception, e: 57 | logging.error(e) 58 | print traceback.format_exc() 59 | result.code = "1001" 60 | result.message = "unknow Exception" 61 | resp = Response(result.get_json()) 62 | return resp 63 | 64 | resp = Response() 65 | resp.data = result.get_json() 66 | resp.mimetype = "application/json" 67 | 68 | return resp 69 | 70 | 71 | 72 | 73 | 74 | xxx = '' 75 | 76 | schedudler = Scheduler(daemonic=False) 77 | 78 | schedudler.add_interval_job(func=plugin.lofter.lofterTask.task, seconds=60) 79 | schedudler.add_interval_job(func=plugin.toutiao.toutiaoTask.toutiao_gallery_task, seconds=60) 80 | schedudler.add_interval_job(func=plugin.toutiao.toutiaoTask.toutiao_news_task, seconds=60) 81 | # schedudler.add_interval_job(func=plugin.lofter.lofterTask.task(''),seconds=20) 82 | 83 | 84 | 85 | if __name__ == '__main__': 86 | schedudler.start() 87 | app.run(port=8888) 88 | 89 | 90 | -------------------------------------------------------------------------------- /plugin/toutiao/toutiaoTask.py: -------------------------------------------------------------------------------- 1 | import traceback 2 | from flask import logging 3 | import model.message 4 | from plugin.toutiao import toutiaoUtils 5 | import utils.timeHelper 6 | import utils.Queue 7 | 8 | 9 | __author__ = 'chenyueling' 10 | 11 | import utils.redisFactory 12 | 13 | mark_news = 'toutiao_news' 14 | mark_gallery = 'toutiao_gallery' 15 | 16 | 17 | def toutiao_news_task(): 18 | redis = utils.redisFactory.getRedis() 19 | set = redis.keys(mark_news + '*') 20 | print set 21 | try: 22 | for cid in set: 23 | 24 | if not utils.timeHelper.time_area(8, 20, 0, 10, 50, 0) and not utils.timeHelper.time_area(18, 20, 0, 18, 25 | 50, 0): 26 | redis.hset(cid, 'notify', 'false') 27 | continue 28 | else: 29 | status = redis.hmget(cid, 'notify')[0] 30 | if status != None and status == 'true': 31 | print status 32 | continue 33 | else: 34 | redis.hset(cid, 'notify', 'true') 35 | 36 | c_id_real = cid.split(':')[1] 37 | sid = redis.hmget(cid, 'sid')[0] 38 | 39 | article = toutiaoUtils.get_toutiao_news() 40 | api_secret = redis.get('api_secret' + ':' + sid) 41 | link = article[toutiaoUtils.LINK] 42 | title = article[toutiaoUtils.TITLE] 43 | summary = article[toutiaoUtils.SUMMARY] 44 | pushData = model.message.ArticleMessage(link, title, summary) 45 | cache_link = redis.hmget(cid, 'cache_link') 46 | print cache_link[0] 47 | print link 48 | print cid 49 | if (cache_link[0] == link): 50 | continue 51 | else: 52 | redis.hmset(cid, {'cache_link': link}) 53 | try: 54 | Q = utils.Queue.Q 55 | print pushData.get_json() 56 | Q.enqueue('utils.push_task.push_article', pushData.get_json(), sid, c_id_real, api_secret) 57 | except Exception, e: 58 | print e 59 | except Exception, e: 60 | # logging.error(e) 61 | print traceback.format_exc() 62 | 63 | 64 | def toutiao_gallery_task(): 65 | redis = utils.redisFactory.getRedis() 66 | set = redis.keys(mark_gallery + '*') 67 | print set 68 | for cid in set: 69 | 70 | if not utils.timeHelper.time_area(8, 30, 0, 10, 50, 0) and not utils.timeHelper.time_area(18, 30, 0, 18, 50, 0): 71 | redis.hset(cid, 'notify', 'false') 72 | continue 73 | else: 74 | status = redis.hmget(cid, 'notify')[0] 75 | if status != None and status == 'true': 76 | continue 77 | else: 78 | redis.hset(cid, 'notify', 'true') 79 | 80 | c_id_real = cid.split(':')[1] 81 | sid = redis.hmget(cid, 'sid')[0] 82 | 83 | article = toutiaoUtils.get_toutiao_gallery() 84 | api_secret = redis.get('api_secret' + ':' + sid) 85 | link = article[toutiaoUtils.LINK] 86 | title = article[toutiaoUtils.TITLE] 87 | pushData = model.message.ArticleMessage(link, title) 88 | 89 | cache_link = redis.hmget(cid, 'cache_link') 90 | 91 | if (cache_link[0] == link): 92 | continue 93 | else: 94 | redis.hmset(cid, {'cache_link': link}) 95 | try: 96 | Q = utils.Queue.Q 97 | print pushData.get_json() 98 | Q.enqueue('utils.push_task.push_article', pushData.get_json(), sid, c_id_real, api_secret) 99 | except Exception, e: 100 | print e 101 | 102 | 103 | -------------------------------------------------------------------------------- /service/serverService.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | __author__ = 'chenyueling' 4 | 5 | import json 6 | import utils.redisFactory 7 | 8 | 9 | 10 | 11 | # { 12 | # "s_data": "{\"date\":\"1\",\"status\":\"下雨\"}", 13 | # "action": "ACTION_SERVICE_CREATE", 14 | # "title": "明天下雨提醒", 15 | # "api_secret": "09ltfmd29f0our68q5bjij2x", 16 | # "sid": "5857", 17 | # "c_data": [ 18 | # { 19 | # "data": "{\"location\":\"珠海\"}", 20 | # "cid": "6f782524-22d4-48fc-b0f6-ab79d49bf178" 21 | # }, 22 | # { 23 | # "data": "{\"location\":\"深圳\"}", 24 | # "cid": "c388eb26-c9f2-41ae-93c5-fdcc0ff8d26a" 25 | # } 26 | # ] 27 | #} 28 | # 29 | #Service创建事件 30 | def action_service_create(service_name, jsonObj): 31 | r = utils.redisFactory.getRedis() 32 | 33 | title = jsonObj['title'] 34 | 35 | api_secret = jsonObj['api_secret'] 36 | 37 | sid = jsonObj['sid'] 38 | 39 | r.set('title' + ':' + sid, title) 40 | 41 | r.set('api_secret' + ':' + sid, api_secret) 42 | 43 | # 44 | s_dict = {} 45 | 46 | if jsonObj.has_key('s_data'): 47 | s_dataStr = jsonObj['s_data'] 48 | s_data_dict = json.loads(s_dataStr) 49 | s_data_dict.update({'sid': sid}) 50 | s_dict.update(s_data_dict) 51 | s_store_dict = r.hgetall('s_data' + ':' + sid) 52 | #合并出最新 53 | s_dict.update(s_store_dict) 54 | #只要是服务端传来的s_data不为空都要存储,如果服务 55 | if s_data_dict.__len__() != 0: 56 | r.hmset('s_data' + ':' + sid, s_dict) 57 | 58 | if jsonObj.has_key('c_data'): 59 | c_data_list_dict = jsonObj['c_data'] 60 | #c_data_list_dict = json.loads(c_data) 61 | for item in c_data_list_dict: 62 | #s_data = jsonObj['s_data'] 63 | data = item['data'] 64 | item.pop('data') 65 | data_dict = json.loads(data) 66 | item.update(s_dict) 67 | item.update(data_dict) 68 | item.update({'sid': sid}) 69 | r.hmset(service_name + ':' + item['cid'], item) 70 | 71 | result = Result('Success', '3000'); 72 | 73 | return result 74 | 75 | 76 | #用户互动事件 77 | def action_service_ding(service_name, jsonObj): 78 | result = Result('Success', '3000'); 79 | return result 80 | 81 | 82 | #ClientService关注数变更事件 83 | def action_service_followed_change(service_name, jsonObj): 84 | print service_name 85 | result = Result('Success', '3000'); 86 | return result 87 | 88 | 89 | # { 90 | # "data": "{\"date\":\"1\",\"status\":\"下雨\"}", 91 | # "action": "ACTION_CLIENT_SERVICE_CREATE", 92 | # "sid": "0556", 93 | # "cid": "bc6e20b4-a0f0-494f-8564-dc2490432e4e" 94 | # } 95 | #ClientService创建事件 96 | def action_client_service_create(service_name, jsonObj): 97 | print jsonObj 98 | print service_name 99 | r = utils.redisFactory.getRedis() 100 | sid = jsonObj['sid'] 101 | c_id_real = jsonObj['cid'] 102 | s_data_dict = r.hgetall('s_data' + ':' + sid) 103 | data = jsonObj['data'] 104 | data_dict = json.loads(data) 105 | data_dict.update({'cid':c_id_real}) 106 | data_dict.update({'sid':sid}) 107 | s_data_dict.update(data_dict) 108 | if s_data_dict.__len__() == 0: 109 | pass 110 | else: 111 | r.hmset(service_name + ':' + c_id_real, s_data_dict) 112 | 113 | result = Result('Success', '3000'); 114 | return result 115 | 116 | 117 | #Service更新事件 118 | def action_service_update(service_name, jsonObj): 119 | r = utils.redisFactory.getRedis() 120 | 121 | title = jsonObj['title'] 122 | 123 | api_secret = jsonObj['api_secret'] 124 | 125 | sid = jsonObj['sid'] 126 | 127 | r.set('title' + ':' + sid, title) 128 | 129 | r.set('api_secret' + ':' + sid, api_secret) 130 | 131 | # 132 | s_dict = {} 133 | 134 | if jsonObj.has_key('s_data'): 135 | s_dataStr = jsonObj['s_data'] 136 | s_data_dict = json.loads(s_dataStr) 137 | s_data_dict.update({'sid': sid}) 138 | s_dict.update(s_data_dict) 139 | s_store_dict = r.hgetall('s_data' + ':' + sid) 140 | #合并出最新 141 | s_dict.update(s_store_dict) 142 | #只要是服务端传来的s_data不为空都要存储,如果服务 143 | if s_data_dict.__len__() != 0: 144 | r.hmset('s_data' + ':' + sid, s_dict) 145 | 146 | if jsonObj.has_key('c_data'): 147 | c_data_list_dict = jsonObj['c_data'] 148 | #c_data_list_dict = json.loads(c_data) 149 | for item in c_data_list_dict: 150 | s_data = jsonObj['s_data'] 151 | item.update(s_dict) 152 | r.hmset(service_name + ':' + item['cid'], item) 153 | 154 | result = Result('Success', '3000'); 155 | return result 156 | 157 | 158 | class Result(object): 159 | def __init__(self, message, code): 160 | self.message = message 161 | self.code = code 162 | 163 | def get_json(self): 164 | return json.dumps(self.__dict__) 165 | -------------------------------------------------------------------------------- /plugin/lofter/net.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | from BeautifulSoup import BeautifulSoup 4 | import urlparse 5 | import urllib 6 | import urllib2 7 | import cookielib 8 | import string 9 | import re 10 | import logging 11 | import traceback 12 | import re 13 | import redis 14 | # 登录的主页面 15 | hosturl = 'http://www.lofter.com' #//自己填写 16 | #post数据接收和处理的页面(我们要向这个页面发送我们构造的Post数据) 17 | posturl = 'https://reg.163.com/logins.jsp' #//从数据包中分析出,处理post请求的url 18 | 19 | #设置一个cookie处理器,它负责从服务器下载cookie到本地,并且在发送请求时带上本地的cookie 20 | cj = cookielib.LWPCookieJar() 21 | cookie_support = urllib2.HTTPCookieProcessor(cj) 22 | opener = urllib2.build_opener(cookie_support, urllib2.HTTPHandler) 23 | urllib2.install_opener(opener) 24 | 25 | #打开登录主页面(他的目的是从页面下载cookie,这样我们在再送post数据时就有cookie了,否则发送不成功) 26 | h = urllib2.urlopen(hosturl) 27 | 28 | #构造header,一般header至少要包含一下两项。这两项是从抓到的包里分析得出的。 29 | headers = { 30 | #'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 31 | #'Accept-Encoding':'gzip,deflate', 32 | #'Accept-Language':'zh-CN,zh;q=0.8,en;q=0.6', 33 | #'Cache-Control':'max-age=0', 34 | #'Connection':'keep-alive', 35 | #'Content-Length':'158', 36 | #'Content-Type':'application/x-www-form-urlencoded', 37 | #'Cookie':'_ntes_nuid=6df1d205baf5a8c60240be009e6f7c53; SID=8d664ab7-5d72-485b-8867-f1eae40553bc; JSESSIONID=adeNFouIl2x2_95sVRKLu; vjuids=1a6cae3bb.14964af2570.0.511d79e; vjlast=1414733440.1414733440.30; _ntes_nnid=4bdf630e8dd1d2ee865be1b985835395,1414733440382; ne_analysis_trace_id=1414733442305; pver_n_f_l_n3=a; PopPushData=1414726245; vinfo_n_f_l_n3=b072541d42cbf206.1.0.1414733442314.0.1414733450494; s_n_f_l_n3=b072541d42cbf2061414733442317; T_INFO=990A52703BFDA09B5C96530F747A8FD5; P_INFO=chen_yueling@163.com|1414733979|2|lofter|00&99|US&1414733949&lofter#US&null#10#0#0|137274&0|mail163&study&blog&lofter¬e|chen_yueling@163.com', 38 | #'Host':'reg.163.com', 39 | 'Origin': 'http://www.lofter.com', 40 | 'Referer': 'http://www.lofter.com/', 41 | 'User-Agent': 'Mozilla/5.0 (X11; Linux i686 (x86_64)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36' 42 | } 43 | #构造Post数据,他也是从抓大的包里分析得出的。 44 | postData = { 45 | 'password': 'rio332137628', 46 | 'type': '1', 47 | 'url': 'http://www.lofter.com/logingate.do', 48 | 'product': 'lofter', 49 | 'savelogin': '1', 50 | #'username':'chenyueling163@gmail.com', 51 | 'username': 'chen_yueling@163.com', 52 | 'domains': 'www.lofter.com' 53 | } 54 | 55 | postDataDwr = { 56 | 'callCount': '1', 57 | 'scriptSessionId': '${scriptSessionId}187', 58 | 'httpSessionId':'', 59 | 'c0-scriptName':'TagBean', 60 | 'c0-methodName': 'search', 61 | 'c0-id': '0', 62 | 'c0-param0': 'string:%E5%BE%AE%E8%B7%9D', 63 | 'c0-param1': 'number:0', 64 | 'c0-param2': 'string:', 65 | 'c0-param3': 'string:excellent', 66 | 'c0-param4': 'boolean:false', 67 | 'c0-param5': 'number:0', 68 | 'c0-param6': 'number:20', 69 | 'c0-param7': 'number:0', 70 | 'c0-param8': 'number:1414935540006', 71 | 'batchId': '370619', 72 | } 73 | 74 | 75 | #需要给Post数据编码 76 | postData = urllib.urlencode(postData) 77 | 78 | postDataDwr = urllib.urlencode(postDataDwr) 79 | 80 | 81 | #通过urllib2提供的request方法来向指定Url发送我们构造的数据,并完成登录过程 82 | request = urllib2.Request(posturl, postData, headers) 83 | print request 84 | try: 85 | response = urllib2.urlopen(request) 86 | print response.geturl() 87 | print response.getcode() 88 | text = response.read() 89 | #print text 90 | #response = urllib2.urlopen('http://www.lofter.com') 91 | #text = response.read() 92 | #f = file('test.html', 'w') 93 | #f.write(text) 94 | soup = BeautifulSoup(text) 95 | 96 | script = soup.find("a") 97 | 98 | #print script['href'] 99 | 100 | response = urllib2.urlopen(script['href']) 101 | 102 | html = response.read() 103 | 104 | #print(html) 105 | f = file('html.html', 'w') 106 | f.write(html) 107 | f.close() 108 | 109 | #urllib2.urlopen('http://www.lofter.com/tag/%E6%A4%8D%E7%89%A9') 110 | 111 | h = { 112 | 'Accept': '* / *', 113 | 'Accept - Encoding':'gzip, deflate', 114 | 'Accept - Language':'zh - CN, zh;q = 0.8, en;q = 0.6', 115 | 'Cache - Control':'max - age = 0', 116 | 'Connection':'keep - alive', 117 | 'Content - Length':'178', 118 | 'Content - Type':'text / plain', 119 | 'Host':'www.lofter.com', 120 | 'Origin':'http://www.lofter.com', 121 | 'Referer':'http://www.lofter.com/tag/%E6%A4%8D%E7%89%A9', 122 | 'User-Agent': 'Mozilla/5.0 (X11; Linux i686 (x86_64)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36' 123 | } 124 | 125 | request = urllib2.Request('http://www.lofter.com/dwr/call/plaincall/TagBean.search.dwr', postDataDwr, h) 126 | 127 | 128 | 129 | #print request.get_header('Cookie') 130 | 131 | response = urllib2.urlopen(request) 132 | 133 | dwr = response.read() 134 | print dwr 135 | print type(dwr) 136 | prog = re.compile(r'http://.*?.lofter.com/post/.*?_.*?"') #"http://yuchunxie.lofter.com/post/c881f_2da737d" 137 | list = prog.findall(dwr) 138 | print list 139 | print len(list) 140 | title_re = re.compile(r'noticeLinkTitle=.*?;') 141 | 142 | 143 | 144 | list_title = title_re.findall(dwr) 145 | 146 | print list 147 | print len(list) 148 | 149 | i = 0 150 | len = len(list_title) 151 | for item in list: 152 | print item.replace('"','') 153 | 154 | if(i < len): 155 | print list_title[i].replace('noticeLinkTitle="','').replace('"','').decode('unicode_escape') 156 | i = i + 1 157 | 158 | 159 | r = redis.Redis(host='localhost', port=6379, db=0) 160 | 161 | #print text 162 | except Exception, e: 163 | print traceback.format_exc() 164 | 165 | #text = response.read() 166 | -------------------------------------------------------------------------------- /plugin/lofter/lofterUtils.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # coding=utf-8 3 | __author__ = 'chenyueling' 4 | 5 | from BeautifulSoup import BeautifulSoup 6 | import urlparse 7 | import urllib 8 | import urllib2 9 | import cookielib 10 | import string 11 | import re 12 | import logging 13 | import traceback 14 | import re 15 | import redis 16 | 17 | TITLE = 'title' 18 | LINK = 'link' 19 | 20 | hosturl = 'http://www.lofter.com' # //自己填写 21 | # post数据接收和处理的页面(我们要向这个页面发送我们构造的Post数据) 22 | posturl = 'https://reg.163.com/logins.jsp' # //从数据包中分析出,处理post请求的url 23 | 24 | # 设置一个cookie处理器,它负责从服务器下载cookie到本地,并且在发送请求时带上本地的cookie 25 | cj = cookielib.LWPCookieJar() 26 | cookie_support = urllib2.HTTPCookieProcessor(cj) 27 | opener = urllib2.build_opener(cookie_support, urllib2.HTTPHandler) 28 | urllib2.install_opener(opener) 29 | 30 | # 打开登录主页面(他的目的是从页面下载cookie,这样我们在再送post数据时就有cookie了,否则发送不成功) 31 | h = urllib2.urlopen(hosturl) 32 | 33 | # 构造header,一般header至少要包含一下两项。这两项是从抓到的包里分析得出的。 34 | headers = { 35 | #'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 36 | #'Accept-Encoding':'gzip,deflate', 37 | #'Accept-Language':'zh-CN,zh;q=0.8,en;q=0.6', 38 | #'Cache-Control':'max-age=0', 39 | #'Connection':'keep-alive', 40 | #'Content-Length':'158', 41 | #'Content-Type':'application/x-www-form-urlencoded', 42 | #'Cookie':'_ntes_nuid=6df1d205baf5a8c60240be009e6f7c53; SID=8d664ab7-5d72-485b-8867-f1eae40553bc; JSESSIONID=adeNFouIl2x2_95sVRKLu; vjuids=1a6cae3bb.14964af2570.0.511d79e; vjlast=1414733440.1414733440.30; _ntes_nnid=4bdf630e8dd1d2ee865be1b985835395,1414733440382; ne_analysis_trace_id=1414733442305; pver_n_f_l_n3=a; PopPushData=1414726245; vinfo_n_f_l_n3=b072541d42cbf206.1.0.1414733442314.0.1414733450494; s_n_f_l_n3=b072541d42cbf2061414733442317; T_INFO=990A52703BFDA09B5C96530F747A8FD5; P_INFO=chen_yueling@163.com|1414733979|2|lofter|00&99|US&1414733949&lofter#US&null#10#0#0|137274&0|mail163&study&blog&lofter¬e|chen_yueling@163.com', 43 | #'Host':'reg.163.com', 44 | 'Origin': 'http://www.lofter.com', 45 | 'Referer': 'http://www.lofter.com/', 46 | 'User-Agent': 'Mozilla/5.0 (X11; Linux i686 (x86_64)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36' 47 | } 48 | #构造Post数据,他也是从抓大的包里分析得出的。 49 | postData = { 50 | 'password': '***********', 51 | 'type': '1', 52 | 'url': 'http://www.lofter.com/logingate.do', 53 | 'product': 'lofter', 54 | 'savelogin': '1', 55 | #'username':'chenyueling163@gmail.com', 56 | 'username': 'chen_yueling@163.com', 57 | 'domains': 'www.lofter.com' 58 | } 59 | 60 | 61 | 62 | 63 | #需要给Post数据编码 64 | postData = urllib.urlencode(postData) 65 | 66 | 67 | def login(): 68 | #通过urllib2提供的request方法来向指定Url发送我们构造的数据,并完成登录过程 69 | request = urllib2.Request(posturl, postData, headers) 70 | try: 71 | response = urllib2.urlopen(request) 72 | print response.geturl() 73 | print response.getcode() 74 | text = response.read() 75 | #print text 76 | #response = urllib2.urlopen('http://www.lofter.com') 77 | #text = response.read() 78 | #f = file('test.html', 'w') 79 | #f.write(text) 80 | soup = BeautifulSoup(text) 81 | 82 | script = soup.find("a") 83 | 84 | #print script['href'] 85 | 86 | response = urllib2.urlopen(script['href']) 87 | 88 | 89 | #html = response.read() 90 | 91 | if response.getcode() == 200: 92 | print 'Login Success' 93 | else: 94 | print 'Login Error' + response.getcode() 95 | 96 | 97 | 98 | 99 | #print(html) 100 | #f = file('html.html', 'w') 101 | #f.write(html) 102 | #f.close() 103 | except Exception, e: 104 | print traceback.format_exc() 105 | 106 | 107 | def get_article_byTag(tag): 108 | #login() 109 | tag = urllib.urlencode({'': tag}).replace('=', '') 110 | h = { 111 | 'Accept': '* / *', 112 | 'Accept - Encoding': 'gzip, deflate', 113 | 'Accept - Language': 'zh - CN, zh;q = 0.8, en;q = 0.6', 114 | 'Cache - Control': 'max - age = 0', 115 | 'Connection': 'keep - alive', 116 | 'Content - Type': 'text / plain', 117 | 'Host': 'www.lofter.com', 118 | 'Origin': 'http://www.lofter.com', 119 | 'Referer': 'http://www.lofter.com/tag/%s' % (tag), 120 | 'User-Agent': 'Mozilla/5.0 (X11; Linux i686 (x86_64)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36' 121 | } 122 | 123 | postDataDwr = { 124 | 'callCount': '1', 125 | 'scriptSessionId': '${scriptSessionId}187', 126 | 'httpSessionId': '', 127 | 'c0-scriptName': 'TagBean', 128 | 'c0-methodName': 'search', 129 | 'c0-id': '0', 130 | 'c0-param0': 'string:%s' % (tag), 131 | 'c0-param1': 'number:0', 132 | 'c0-param2': 'string:', 133 | 'c0-param3': 'string:new', 134 | 'c0-param4': 'boolean:false', 135 | 'c0-param5': 'number:0', 136 | 'c0-param6': 'number:20', 137 | 'c0-param7': 'number:0', 138 | 'c0-param8': 'number:0', 139 | 'batchId': '370619', 140 | } 141 | postDataDwr = urllib.urlencode(postDataDwr) 142 | 143 | request = urllib2.Request('http://www.lofter.com/dwr/call/plaincall/TagBean.search.dwr', postDataDwr, h) 144 | 145 | 146 | 147 | #print request.get_header('Cookie') 148 | 149 | response = urllib2.urlopen(request) 150 | 151 | dwr = response.read() 152 | #dwr data 153 | print dwr 154 | #print type(dwr) 155 | #reg match 156 | prog = re.compile(r'http://.*?.lofter.com/post/.*?_.*?"') #"http://yuchunxie.lofter.com/post/c881f_2da737d" 157 | list = prog.findall(dwr) 158 | #print list 159 | 160 | title_re = re.compile(r'noticeLinkTitle=.*?;') 161 | 162 | list_title = title_re.findall(dwr) 163 | 164 | #print list 165 | 166 | i = 0 167 | article_list = [] 168 | 169 | for item in list: 170 | article = {} 171 | #print item.replace('"', '') 172 | article = {LINK: item.replace('"', '')} 173 | if (i < list_title.__len__()): 174 | #print list_title[i].replace('noticeLinkTitle="', '').replace('"', '').decode('unicode_escape') 175 | article.update({ 176 | TITLE: list_title[i].replace('noticeLinkTitle="', '').replace('"', '').replace(';', '').decode( 177 | 'unicode_escape')}) 178 | print article 179 | article_list.append(article) 180 | #print 181 | i = i + 1 182 | return article_list 183 | 184 | #test 185 | print urllib.urlencode({'': '原画'}).replace('=', '') 186 | get_article_byTag(urllib.urlencode({'': '原画'}).replace('=', '')) 187 | -------------------------------------------------------------------------------- /html.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | LOFTER 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 19 | 20 | 21 | 22 | 23 | 24 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | LOFTER for ipad —— 记录生活,发现同好~~ 35 | 点击下载 36 | 关闭 37 | 38 | 39 | 40 | 意见反馈 41 | 42 | 43 | LOFTER-网易轻博 44 | 45 | 46 | 首页5 47 | 浏览 48 | ART 49 | instagram备份NEW 50 | 51 | 更多 52 | 53 | 54 | 55 | 56 | 57 | 帐号设置 58 | 寻找好友 59 | 导入导出 60 | 移动客户端 61 | UAPP-创建个人应用 62 | 帮助及反馈 63 | 退出 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 搜索标签、人 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 羊毛毡 94 | 95 | 20篇新文章 96 | 97 | 98 | 99 | 100 | 手账 101 | 102 | 79篇新文章 103 | 104 | 105 | 106 | 107 | 橡皮章 108 | 109 | 394篇新文章 110 | 111 | 112 | 113 | 114 | 手工 115 | 116 | 30篇新文章 117 | 118 | 119 | 120 | 121 | 动物 122 | 123 | 13917篇新文章 124 | 125 | 126 | 127 | 128 | 狗 129 | 130 | 8290篇新文章 131 | 132 | 133 | 134 | 135 | 猫 136 | 137 | 56524篇新文章 138 | 139 | 140 | 141 | 142 | 树洞 143 | 144 | 315篇新文章 145 | 146 | 147 | 148 | 149 | 小说 150 | 151 | 8331篇新文章 152 | 153 | 154 | 155 | 156 | 文摘 157 | 158 | 3篇新文章 159 | 160 | 161 | 162 | 163 | 诗歌 164 | 165 | 8854篇新文章 166 | 167 | 168 | 169 | 170 | 随笔 171 | 172 | 16904篇新文章 173 | 174 | 175 | 176 | 177 | 现场 178 | 179 | 7211篇新文章 180 | 181 | 182 | 183 | 184 | 音乐 185 | 186 | 74462篇新文章 187 | 188 | 189 | 190 | 191 | 乐评 192 | 193 | 10839篇新文章 194 | 195 | 196 | 197 | 198 | 美剧 199 | 200 | 32篇新文章 201 | 202 | 203 | 204 | 205 | 海报 206 | 207 | 54篇新文章 208 | 209 | 210 | 211 | 212 | 设计 213 | 214 | 12723篇新文章 215 | 216 | 217 | 218 | 219 | 字体设计 220 | 221 | 3531篇新文章 222 | 223 | 224 | 225 | 226 | UI 227 | 228 | 5587篇新文章 229 | 230 | 231 | 232 | 233 | 游记 234 | 235 | 2095篇新文章 236 | 237 | 238 | 239 | 240 | 风景 241 | 242 | 27775篇新文章 243 | 244 | 245 | 246 | 247 | cosplay 248 | 249 | 5288篇新文章 250 | 251 | 252 | 253 | 254 | 动漫 255 | 256 | 338篇新文章 257 | 258 | 259 | 260 | 261 | 烘焙 262 | 263 | 75篇新文章 264 | 265 | 266 | 267 | 268 | 菜谱 269 | 270 | 3443篇新文章 271 | 272 | 273 | 274 | 275 | 深夜食堂 276 | 277 | 14篇新文章 278 | 279 | 280 | 281 | 282 | CG 283 | 284 | 15篇新文章 285 | 286 | 287 | 288 | 289 | 插画推荐 290 | 291 | 22篇新文章 292 | 293 | 294 | 295 | 296 | 涂鸦 297 | 298 | 20614篇新文章 299 | 300 | 301 | 302 | 303 | 水彩 304 | 305 | 456篇新文章 306 | 307 | 308 | 309 | 310 | 原画 311 | 312 | 3746篇新文章 313 | 314 | 315 | 316 | 317 | 单品 318 | 319 | 90篇新文章 320 | 321 | 322 | 323 | 324 | 人像 325 | 326 | 113883篇新文章 327 | 328 | 329 | 330 | 331 | 胶片 332 | 333 | 29650篇新文章 334 | 335 | 336 | 337 | 338 | 手机摄影 339 | 340 | 120189篇新文章 341 | 342 | 343 | 344 | 345 | 黑白 346 | 347 | 74589篇新文章 348 | 349 | 350 | 351 | 352 | 自拍 353 | 354 | 649篇新文章 355 | 356 | 357 | 358 | 359 | 旅行 360 | 361 | 7075篇新文章 362 | 363 | 364 | 365 | 366 | 电影 367 | 368 | 5075篇新文章 369 | 370 | 371 | 372 | 373 | 搭配 374 | 375 | 3520篇新文章 376 | 377 | 378 | 379 | 380 | 美食 381 | 382 | 20340篇新文章 383 | 384 | 385 | 386 | 387 | 插画 388 | 389 | 27867篇新文章 390 | 391 | 392 | 393 | 394 | 摄影 395 | 396 | 24428篇新文章 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 文字 416 | 图片 417 | 音乐 418 | 视频 419 | 420 | 421 | 你还有一篇未发布的文章。查看 422 | 查看 423 | 424 | 加载中 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 陈岳陵chenyueling.lofter.com99 434 | 435 | 436 | 437 | 438 | 创建新主页 439 | 440 | 441 | 442 | 443 | 444 | 文章0 445 | 446 | 447 | 448 | 自动发布0 449 | 草稿0 450 | 451 | 私信0 452 | 453 | 个人主页设置 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 关注1 468 | 发现达人 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 载入更多内容 500 | 501 | 回到顶部 502 | 503 | 想用@提到谁? 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 喜欢的文章 570 | 关注的博客 571 | 发私信 572 | 取消关注 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 打开新页 590 | 591 | 592 | 593 | hisname关注转载自hername关注来源关注(仅博客成员可见)- 推荐者 hername- LOFTER推荐屏蔽过滤2.1不推去精 594 | 595 | 596 | 597 | 598 | #生活#生活#生活#生活 599 | 600 | 601 | 移动内容发布编辑删除发布加黑热度(1)评论(1)转载分享推荐喜欢 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 打开新页 626 | 627 | 628 | 629 | hisname转载自hername来源(仅博客成员可见)- 推荐者 hername 630 | 631 | 632 | 633 | 634 | #生活#生活#生活#生活 635 | 636 | 637 | 移动内容编辑删除发布 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 展开 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 查看完整图片 667 | 668 | 查看大图 669 | 670 | 671 | 672 | 673 | 展开 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 展开 684 | 685 | 686 | {list photos as photo} 687 | 688 | 689 | 690 | 691 | ${photos.length||2} 692 | 693 | 694 | 695 | {if photo_index==0}{break}{/if} 696 | {/list} 697 | 698 | {list photos as photo} 699 | 700 | 701 | 702 | {if !!expand} 703 | 704 | ${photos.length||2} 705 | 706 | {/if} 707 | 708 | 709 | 710 | 查看大图 711 | 712 | {if !expand}${spescape(captions[photo_index])}{/if} 713 | 714 | {if !!expand}{break}{/if} 715 | {/list} 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 展开 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 展开 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 展开 792 | 793 | 794 | 删除 795 | 796 | 797 | 798 | 提问 799 | 800 | 801 | 802 | 803 | 加黑 804 | 删除 805 | 仅回答 806 | 回答并发布 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 品牌${make||'-'} 818 | 型号${model||'-'} 819 | 焦距${focalLength||'-'} 820 | 光圈${apertureValue||'-'} 821 | 快门速度${exposureTime||'-'} 822 | ISO${isoSpeedRatings||'-'} 823 | 曝光补偿${exposureBiasValue||'-'} 824 | 镜头${lens||'-'} 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | {if defined('posts')&&posts.length>0} 838 | {list posts as post} 839 | 840 | {if post_index < 3} 841 | {if post.type == 1 || post.type == 5} 842 | 843 | {if !!post.title}${post.title|escape}{/if} 844 | {if !!post.digest}${post.digest}{/if} 845 | 846 | 847 | {/if} 848 | {if post.type == 2} 849 | 850 | 851 | 852 | 853 | {/if} 854 | {if post.type == 3} 855 | 856 | {if !!post.showimages}{/if} 857 | 858 | 859 | 860 | {/if} 861 | {if post.type == 4} 862 | 863 | {if !!post.showimages}{/if} 864 | 865 | 866 | 867 | {/if} 868 | {/if} 869 | 870 | {/list} 871 | {else} 872 | 暂无文章 873 | {/if} 874 | 875 | 876 | 877 | 878 | 879 | 880 | 881 | ${data.name|escape} 882 | 文章 ${data.publicPostCount}喜欢 ${data.FavoritePostCount}关注 ${data.followerCount} 883 | 884 | 885 | 886 | 887 | 888 | 889 | 890 | {if data.msgRank == 1}私信{/if} 891 | {if data.askSetting == 1}提问{/if} 892 | 893 | 894 | 895 | 896 | 已关注 897 | +关注 898 | 899 | 900 | 901 | 902 | 903 | 904 | 905 | 906 | 907 | 908 | 909 | 910 | 911 | 912 | 913 | 914 | 915 | 916 | 917 | 918 | 919 | 920 | 飘落 921 | 文章 44 922 | 923 | 924 | 925 | 926 | 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 | 935 | 936 | 937 | 938 | 939 | 940 | 941 | 942 | 943 | 944 | ${tag|escape} 945 | 946 | 947 | 948 | 949 | 950 | 951 | 952 | 953 | {if defined('posts')&&posts.length>0} 954 | {list posts as post} 955 | 956 | {if post_index < 3} 957 | {if post.type == 1 || post.type == 5} 958 | 959 | {if !!post.title}${post.title|escape}{/if} 960 | {if !!post.digest}${post.digest}{/if} 961 | 962 | 963 | {/if} 964 | {if post.type == 2} 965 | 966 | 967 | 968 | 969 | {/if} 970 | {if post.type == 3} 971 | 972 | {if !!post.showimages}{/if} 973 | 974 | 975 | 976 | {/if} 977 | {if post.type == 4} 978 | 979 | {if !!post.showimages}{/if} 980 | 981 | 982 | 983 | {/if} 984 | {/if} 985 | 986 | {/list} 987 | {else} 988 | 暂无文章 989 | {/if} 990 | 991 | 992 | 993 | 994 | 995 | 996 | 997 | 998 | 999 | 1000 | 1001 | 1002 | 1003 | 1004 | 1005 | 转载喜欢 1006 | 1007 | 1008 | 1009 | 1010 | 1011 | 1012 | 加关注LOFTER精选 1013 | 1014 | 1015 | 1016 | 1017 | 1018 | 1019 | 1020 | 1021 | 1022 | 1023 | 1024 | 1025 | 1026 | 1027 | 1028 | 1029 | 1030 | 1031 | 1032 | 1033 | 1034 | 1035 | 1036 | 1037 | 1038 | 1039 | 1040 | 1041 | 1042 | 1043 | 1044 | 1045 | 1046 | 1047 | 1048 | 1049 | 1050 | 1051 | 1052 | 1053 | 1054 | 1055 | 1056 | 标签 1057 | 博客 1058 | 我的文章 1059 | 1060 | 1061 | 1062 | 1063 | 1064 | 1065 | 1066 | 1067 | 1068 | 1069 | 1070 | 通知关闭 1071 | 1072 | 1073 | 1074 | 1075 | 1076 | 1077 | 1078 | 完 成 1079 | 1080 | 1081 | 1082 | 1083 | 1084 | 1085 | 1086 | 摄影 1087 | 胶片 1088 | 音乐 1089 | 绘画 1090 | 设计 1091 | 手工 1092 | 文字 1093 | 美食 1094 | 艺术 1095 | 手机摄影 1096 | cosplay 1097 | 1098 | 1099 | 1100 | 已关注了0个用户 1101 | 全部关注 1102 | 1103 | 1104 | 1105 | 1106 | 1107 | 1108 | 完 成 1109 | 1110 | 1111 | 1112 | 1113 | {if defined('c')&&c.length>0} 1114 | {list c as x} 1115 | {if !!x && !!x.blogInfo} 1116 | ${x.blogInfo.blogNickName|default:''|escape}${x.finalRecReason|default:''|escape}关注 1117 | {/if} 1118 | {/list} 1119 | {/if} 1120 | 1121 | this.p={editReblogFromPersonalPage:false,goPublishData:"null",allowUploadDIYMusic:false,v:'',isAdvancedBrowser:true,targetBlogInfo:{"blogId":482379424,"blogName":"chenyueling","blogNickName":"陈岳陵","bigAvaImg":"http://imglf2.ph.126.net/6G0M056h5hBo7oGv0lahtQ==/2452209997120091708.jpg","keyTag":"","selfIntro":"","postAddTime":0,"commentRank":10,"imageProtected":false,"imageStamp":false,"imageDigitStamp":false,"blogStat":null},lastCCType:-1,postOverNum:false,blogList:[{"id":484380425,"userId":482379424,"blogId":482379424,"joinTime":1414733615629,"role":10,"newNoticeCount":0,"newRecommendNoticeCount":0,"newActivityTagNoticeCount":0,"newArtNoticeCount":0,"newFriendCount":0,"newFollowingUAppCount":0,"blogInfo":{"blogId":482379424,"blogName":"chenyueling","blogNickName":"陈岳陵","bigAvaImg":"http://imglf2.ph.126.net/6G0M056h5hBo7oGv0lahtQ==/2452209997120091708.jpg","keyTag":"","selfIntro":"","postAddTime":0,"commentRank":10,"imageProtected":false,"imageStamp":false,"imageDigitStamp":false,"blogStat":null}}],submiterBlogInfo:"null",ue_cfg_develop:false,ue_js_version:'20140722',mydomains:{},tag:'',visitorId:482379424,targetBlogId:482379424,guide:0,blogName:'chenyueling',nickname:'陈岳陵',avaImg:'http://imglf2.ph.126.net/6G0M056h5hBo7oGv0lahtQ==/2452209997120091708.jpg',radarAdPercent:30, radarActivityTagPercent:30}; 1122 | 1123 | 1124 | 1125 | 1198 | 1199 | 1200 | 1201 | --------------------------------------------------------------------------------
LOFTER for ipad —— 记录生活,发现同好~~
${spescape(captions[photo_index])}
加关注LOFTER精选
已关注了0个用户