Skip to content

Commit

Permalink
add timeline and list timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
bigeagle committed Feb 27, 2011
1 parent 4fd12e3 commit 788b045
Show file tree
Hide file tree
Showing 24 changed files with 879 additions and 15 deletions.
6 changes: 3 additions & 3 deletions app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ handlers:
upload: static/robots.txt


- url: /cat
static_files: static/files/cat_s_daily.html
upload: static/files/cat_s_daily.html
#- url: /cat
# static_files: static/files/cat_s_daily.html
# upload: static/files/cat_s_daily.html

# All URLs beginning with /stylesheets are treated as paths to static files in
# the stylesheets/ directory. Note that static_dir handlers do not use a
Expand Down
4 changes: 3 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
KEY_FOBACK_ALL = '/AutoFollowBack' # 回Fo动作的触发名 (注意要和Cron.yaml中的保持同步)
# 请修改此 CronJob Key 为其他人无法猜到的字符串,以防被人利用 (注意要和Cron.yaml中的保持同步)
KEY_CRONJOB = '/InputYourCronJobKeyHere'
URL_SENDTWEET = '/backdoor2tweet' # 手动发Tweet到Twitter (例如请求: /tweet2bot?msg='Hello World!')
URL_SENDTWEET = '/tweet' # 手动发Tweet到Twitter (例如请求: /tweet2bot?msg='Hello World!')


## 个性化提示语设置
Expand All @@ -41,6 +41,8 @@

## 其他参数设置
MENTIONS_COUNT = 15 # 提及页面的显示条数
HOME_COUNT = 30 # 主页面显示条数


# 单词的连接符和分隔符
TW_WORD_LINK = ' - ' # 单元格A和单元格B之间的连接符
Expand Down
Binary file added config.pyc
Binary file not shown.
5 changes: 0 additions & 5 deletions cron.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
cron:

- description: (Cron Job) to execute program
url: /InputYourCronJobKeyHere
schedule: every 5 mins
timezone: Asia/Shanghai

- description: Auto follow back
url: /AutoFollowBack
schedule: every 23 hours
Expand Down
Empty file added cscope.files
Empty file.
Binary file added db_util.pyc
Binary file not shown.
50 changes: 46 additions & 4 deletions index.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import config # r14 add @20101215 独立bot的配置文件
import db_util # r2 add @20101026 将数据库相关操作独立出来

sys.path.insert(0, 'tweepy.zip')
#sys.path.insert(0, 'tweepy.zip')
import tweepy

# r2 add @20101026 替换csv为xls文件,加速读取
Expand Down Expand Up @@ -112,6 +112,49 @@ def get(self):
path = os.path.join(os.path.dirname(__file__), 'template/mentions.html')
self.response.out.write(template.render(path, { 'mentions': mentions }))

# TimeLine
class GetTimeline(webapp.RequestHandler):
def get(self):
auth = tweepy.OAuthHandler(config.CONSUMER_KEY, config.CONSUMER_SECRET)
auth.set_access_token(config.ACCESS_TOKEN, config.ACCESS_SECRET)
api = tweepy.API(auth)
timeline = tweepy.Cursor(api.home_timeline).items(config.HOME_COUNT)

logging.info('Check Timeline')

path = os.path.join(os.path.dirname(__file__), 'template/timeline.html')
self.response.out.write(template.render(path, { 'timeline': timeline }))

# RT list

class GetList(webapp.RequestHandler):
def get(self):
count=config.HOME_COUNT
auth = tweepy.OAuthHandler(config.CONSUMER_KEY, config.CONSUMER_SECRET)
auth.set_access_token(config.ACCESS_TOKEN, config.ACCESS_SECRET)
api = tweepy.API(auth)

max_id = self.request.get('max_id')
#logging.info(max_id)

if max_id=='':
RT=api.list_timeline(owner='xdlinux',slug='rt-2',per_page=count+1)
#RT = tweepy.Cursor(api.list_timeline,owner='xdlinux',slug='rt-2').items(count)
max_id=RT[-1].id
RT.pop()
else:
max_id=int(max_id)
RT=api.list_timeline(owner='xdlinux',slug='rt-2',max_id=max_id,per_page=count+1)
#RT = tweepy.Cursor(api.list_timeline,owner='xdlinux',slug='rt-2',max_id=max_id).items(count)
max_id=RT[-1].id
RT.pop()

logging.info('Check list')

next="RT?max_id=%d" % max_id

path = os.path.join(os.path.dirname(__file__), 'template/index.html')
self.response.out.write(template.render(path, { 'RT': RT ,'NEXT': next}))

# 自动回Fo所有新的Followers
class FollowAllNewcomers(webapp.RequestHandler):
Expand Down Expand Up @@ -139,8 +182,6 @@ def get(self):

self.response.out.write('Success create_friendship() with %d user, %d skiped.' % (suc_count, err_count))



#
# Cron Job
#
Expand Down Expand Up @@ -241,7 +282,8 @@ def get(self):



application = webapp.WSGIApplication([('/', MainPage),
application = webapp.WSGIApplication([('/RT', GetList),
('/timeline',GetTimeline),
(config.URL_CURWORD, ShowCurrentWord),
(config.URL_MENTIONS, GetMentions),
(config.KEY_FOBACK_ALL, FollowAllNewcomers),
Expand Down
574 changes: 574 additions & 0 deletions tags

Large diffs are not rendered by default.

Binary file added template/.index.html.swp
Binary file not shown.
127 changes: 127 additions & 0 deletions template/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Timeline @xdlinux</title>
<style>
* {
margin: 0px;
padding: 0px;
}

div {
display: block;
}

#page-outer {
margin: 0px auto;
max-width: 1120px;
min-width: 1000px;
padding-top: 10px;
text-align: center;
}
#component {
margin-left: auto;
margin-right: auto;
max-width: 720px;
min-width: 720px;
width: 720px;
overflow: hidden;
position: relative;
text-align: left;
z-index: 1;
}

.tweet {
padding: 5px 10px 3px 10px;
margin-top: 5px;
border-left: 1px solid #CCCCCC;
border-bottom: 1px solid #CCCCCC;
background-color: #E8F0FC;
}
.tweet-row {
display: block;
line-height: 15px;
position: relative;
color: #333;
}

.tweet-user-block {
float: left;
}
.tweet-user-block img {
height: 48px;
width: 48px;
}
.tweet-user-block-name {
line-height: 18px;
margin-left: 49px;
padding-top: 2px;
padding-left: 10px;
padding-bottom: 2px;
color: #0084B4;
}
.tweet-user-block-desc {
font-size: 14px;
line-height: 16px;
margin-left: 49px;
min-height: 36px;
padding-top: 2px;
padding-left: 10px;
padding-bottom: 4px;
color: #AAA;
}

.tweet-text {
font-family: Arial, 'Helvetica Neue', sans-serif;
line-height: 19px;
padding: 0px;
word-wrap: break-word;
margin-left: 10px;
min-height: 48px;
}
.tweet-timestamp {
font-size: 13px;
line-height: 22px;
margin-left: 10px;
}
.tweet-timestamp a {
color: #999;
}
</style>
</head>
<body>
<div id="page-outer">
<div id="component">
{% for status in RT %}
<div class="tweet">
{% if status.user %}
<div class="tweet-row">
<div class="tweet-user-block">
<img src="{{ status.user.profile_image_url }}" />
</div>
<div class="tweet-user-block-name">
<b>@{{ status.user.screen_name }}</b>
</div>
<div class="tweet-user-block-desc">
{{ status.user.description }}
{{ status.id}}
</div>
</div>
{% endif %}

<div class="tweet-row">
<div class="tweet-text">
{{ status.text }}
</div>
</div>
<div class="tweet-row">
<span class="tweet-timestamp"><a href="http://twitter.com/{{ status.user.screen_name }}/status/{{ status.id }}" target="_blank">{{ status.created_at }}</a></span>
</div>
</div>
{% endfor %}
</div>
<a href={{NEXT}}>next page</a>
</div>

</body>
</html>
4 changes: 2 additions & 2 deletions template/mentions.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>mention @zwbot</title>
<title>mention @xdlinux</title>
<style>
* {
margin: 0px;
Expand Down Expand Up @@ -121,4 +121,4 @@
</div>
</div>
</body>
</html>
</html>
124 changes: 124 additions & 0 deletions template/timeline.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Timeline @xdlinux</title>
<style>
* {
margin: 0px;
padding: 0px;
}

div {
display: block;
}

#page-outer {
margin: 0px auto;
max-width: 1120px;
min-width: 1000px;
padding-top: 10px;
text-align: center;
}
#component {
margin-left: auto;
margin-right: auto;
max-width: 720px;
min-width: 720px;
width: 720px;
overflow: hidden;
position: relative;
text-align: left;
z-index: 1;
}

.tweet {
padding: 5px 10px 3px 10px;
margin-top: 5px;
border-left: 1px solid #CCCCCC;
border-bottom: 1px solid #CCCCCC;
background-color: #E8F0FC;
}
.tweet-row {
display: block;
line-height: 15px;
position: relative;
color: #333;
}

.tweet-user-block {
float: left;
}
.tweet-user-block img {
height: 48px;
width: 48px;
}
.tweet-user-block-name {
line-height: 18px;
margin-left: 49px;
padding-top: 2px;
padding-left: 10px;
padding-bottom: 2px;
color: #0084B4;
}
.tweet-user-block-desc {
font-size: 14px;
line-height: 16px;
margin-left: 49px;
min-height: 36px;
padding-top: 2px;
padding-left: 10px;
padding-bottom: 4px;
color: #AAA;
}

.tweet-text {
font-family: Arial, 'Helvetica Neue', sans-serif;
line-height: 19px;
padding: 0px;
word-wrap: break-word;
margin-left: 10px;
min-height: 48px;
}
.tweet-timestamp {
font-size: 13px;
line-height: 22px;
margin-left: 10px;
}
.tweet-timestamp a {
color: #999;
}
</style>
</head>
<body>
<div id="page-outer">
<div id="component">
{% for status in timeline %}
<div class="tweet">
{% if status.user %}
<div class="tweet-row">
<div class="tweet-user-block">
<img src="{{ status.user.profile_image_url }}" />
</div>
<div class="tweet-user-block-name">
<b>@{{ status.user.screen_name }}</b>
</div>
<div class="tweet-user-block-desc">
{{ status.user.description }}
</div>
</div>
{% endif %}

<div class="tweet-row">
<div class="tweet-text">
{{ status.text }}
</div>
</div>
<div class="tweet-row">
<span class="tweet-timestamp"><a href="http://twitter.com/{{ status.user.screen_name }}/status/{{ status.id }}" target="_blank">{{ status.created_at }}</a></span>
</div>
</div>
{% endfor %}
</div>
</div>
</body>
</html>
Binary file modified tweepy/__init__.pyc
Binary file not shown.
Binary file modified tweepy/api.pyc
Binary file not shown.
Binary file modified tweepy/auth.pyc
Binary file not shown.
Binary file modified tweepy/binder.pyc
Binary file not shown.
Binary file modified tweepy/cache.pyc
Binary file not shown.
Binary file modified tweepy/cursor.pyc
Binary file not shown.
Binary file modified tweepy/error.pyc
Binary file not shown.
Binary file modified tweepy/models.pyc
Binary file not shown.
Binary file modified tweepy/oauth.pyc
Binary file not shown.
Binary file modified tweepy/parsers.pyc
Binary file not shown.
Binary file modified tweepy/streaming.pyc
Binary file not shown.
Binary file modified tweepy/utils.pyc
Binary file not shown.

0 comments on commit 788b045

Please sign in to comment.