|
大家最近都在热议古城钟楼的红火。不是加V号、不是官方号、不是皇冠会员。没有拟人化,没有段子、没有运营。1天之内从1万不到的粉丝新增了20多万并且还在持续传播和增长粉丝。我不研究它是怎么红起来的,但写个类似的程序实现它却很容易,程序才100行左右: * L9 V! Y8 x- G' [1 W
先来普及一下地支时间与北京时间的对应关系: - 【子时】夜半,又名子夜、中夜:十二时辰的第一个时辰。(北京时间23时至次日01时)。
- 【丑时】鸡鸣,又名荒鸡:十二时辰的第二个时辰。(北京时间01时至03时)。
- 【寅时】平旦,又称黎明、早晨、日旦等:时是夜与日的交替之际。(北京时间03时至05时)。
- 【卯时】日出,又名日始、破晓、旭日等:指太阳刚刚露脸,冉冉初升的那段时间。(北京时间05时至07时)。
- 【辰时】食时,又名早食等:古人“朝食”之时也就是吃早饭时间,(北京时间07时至09时)。
- 【巳时】隅中,又名日禺等:临近中午的时候称为隅中。(北京时间09时至11时)。
- 【午时】日中,又名日正、中午等:(北京时间11时至13时)。
- 【未时】日昳,又名日跌、日央等:太阳偏西为日跌。(北京时间13时至15时)。
- 【申时】哺时,又名日铺、夕食等:(北京时间15时至17时)。
- 【酉时】日入,又名日落、日沉、傍晚:意为太阳落山的时候。(北京时间17时至19时)。
- 【戌时】黄昏,又名日夕、日暮、日晚等:此时太阳已经落山,天将黑未黑。天地昏黄,万物朦胧,故称黄昏。(北京时间19时至21时)。
- 【亥时】人定,又名定昏等:此时夜色已深,人们也已经停止活动,安歇睡眠了。人定也就是人静。(北京时间21时至23时)。
6 F4 Q3 S" p% S% ]/ u" D: B $ ^; G: v. H6 F2 z2 M! q+ M7 s
然后我们来分析一下它昨天发布的内容 - 1月8日00:00来自Weico.iPhone 【子时】
- 1月8日02:00来自Weico.iPhone 【丑时】铛~铛~
- 1月8日04:00来自Weico.iPhone 【寅时】铛~铛~铛~铛~
- 1月8日06:00来自Weico.iPhone 【卯时】铛~铛~铛~铛~铛~铛~
- 1月8日08:00来自Weico.iPhone 【辰时】铛~铛~铛~铛~铛~铛~铛~铛~
- 1月8日10:00来自Weico.iPhone 【巳时】铛~铛~铛~铛~铛~铛~铛~铛~铛~铛~
- 1月8日12:00来自Weico.iPhone 【午时】
- 1月8日14:00来自Weico.iPhone 【未时】铛~铛~
- 1月8日16:00来自Weico.iPhone 【申时】铛~铛~铛~铛~
- 1月8日18:00来自Weico.iPhone 【酉时】铛~铛~铛~铛~铛~铛~
- 1月8日20:00来自Weico.iPhone 【戌时】铛~铛~铛~铛~铛~铛~铛~铛~
- 1月8日22:00来自Weico.iPhone 【亥时】铛~铛~铛~铛~铛~铛~铛~铛~铛~铛~3 r4 Q# n7 U( E9 C$ f" Z/ o( Y. r3 M
5 @/ [9 w$ J* D' h1 ~" @3 {根据上面,得出它有以下规律: - 每两个小时发布一条微博,
- 发布时间是偶数小时的0分,这个时间并不是地支时间的开始时间,而是正中间的那个时间点
- 内容是相应的地支时间,加上根据时间而变化的“铛~”的次数,
- “铛~”的次数与时有关,12小时以前与小时相同,12小时以后与[小时减12]相同。; {2 y3 C3 P | p$ {# ~0 W" }
西安钟楼里的钟就是这样敲的吗?去过钟楼一次,没登上去,也没注意。 4 H x& ~7 Q& A2 C- F2 J/ L
完整代码如下: 需要自行修改App相关值: 8 g0 H* {% r+ J Z ~) q
( V- I1 u7 w! h# V h0 q5 W- <p style="font: 14px/25px verdana, Arial, Helvetica, sans-serif; margin: 10px auto; padding: 0px; color: rgb(51, 51, 51); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(255, 255, 255); -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;"><span style="margin: 0px; padding: 0px; color: rgb(255, 0, 0);"></span> </p>
复制代码- using System;% @# y# \( D6 j
- using System.Collections.Generic;* b K2 S6 t3 @: e# J6 L
- using System.Text;
' }" k" b# b5 ?! T7 i7 ?9 C - using NetDimension.Weibo;3 j7 S+ K- d9 l+ i* H1 \
- using System.Timers;
& _( d( K: y4 ~" p$ U" n - using System.Globalization;
9 M, B6 t. F. @1 e - / F" z9 I6 Q" ~8 H' w
- namespace WeiboTimer
' ?7 y: R X$ h2 j% m - {$ M# @% T9 o. v: W) Q# @! l
- class Program; l5 s: T: n( k @* b- ~
- {; W; `, m6 k' ]6 a5 J
- static string AppKey = "********";( j0 l: J" M8 i! S
- static string AppSecret = "*******";2 Q- R+ M, w7 X: A- q0 ^
- static string CallbackUrl = "****************";
8 }* L# E. `* [% i - static Timer t = new Timer();
5 \2 [* i# v+ C/ v - static OAuth oauth = null;! K& f' i2 g# ~/ }
- static Client Sina = null;
) N" _- w1 D3 s* \; c n9 _
6 R7 V1 z; o3 h4 G+ }' u$ g( p6 A- static void Main(string[] args)' q% G9 Z. V, K
- {
; l8 Z1 T/ a( A' q u2 G* Y6 o - oauth = Authorize();
: j6 q; @. t$ |2 N - if (!string.IsNullOrEmpty(oauth.AccessToken)){Console.Write("登录成功!");}+ v! w) V+ [; m; m% s
% I3 v% } u( ]- Sina = new Client(oauth);0 g6 a- K+ V* `8 v9 p0 f B, X9 P
- string uid = Sina.API.Entity.Account.GetUID();" y8 K9 p7 V) E1 J
- var entity_userInfo = Sina.API.Entity.Users.Show(uid);
$ ]5 V7 ]8 Q: h - Console.WriteLine("昵称:{0},微博地址:http://weibo.com/{1}", entity_userInfo.ScreenName, entity_userInfo.ProfileUrl);" C* s4 s- c- W, F- _8 U
- r! W1 e: V7 b3 v4 ^8 @3 P- try
" p+ J! P, w: O( H# k# T: F - {( N( }, z" Z, l7 |2 ~8 `
- t.Interval = 1000 * 60; //设置间隔时间为1分钟, R$ Q1 `* E9 c1 ]6 V
- t.Elapsed += new ElapsedEventHandler(TimerElapsedEvent); //到达时间的时候执行事件;
% l5 N- h3 n- a$ p5 _. c - t.AutoReset = true; //设置是执行一次(false)还是一直执行(true);
( f0 ~5 _' |) X# S+ ~8 [ - t.Start(); //启动Timer对象; . [* P ]; R! ]0 h( J/ i; |! q2 a
- }( K* I$ `: F9 @
- catch (Exception ex)
5 k& R3 k, y! v/ o! G - {3 P9 @# ~! i& y2 A$ K8 q- l
- Console.WriteLine("定时任务异常:" + ex.Message);3 Q' d1 t- A2 W+ c
- t.Stop();
0 h0 L* Z) w0 R! m2 L) h3 X0 h - }% e( D A+ Q( V- S8 |$ U4 r
- Console.WriteLine("定时任务开始工作。。。");" H; |/ u/ ]. K0 S/ v" \
- Console.ReadKey();
. q0 b% N0 P- W0 J - }* ]# \4 W% ?$ r
- . N+ ]$ }4 [8 Y8 v! n V2 z+ n
- static OAuth Authorize()
0 ]) j) E7 U9 L$ b - {& S5 W) U" V$ D, ~. n
- OAuth o = new OAuth(AppKey, AppSecret, CallbackUrl);) K9 D! C1 n! o; Q$ a* |/ w
- while (!ClientLogin(o))% m- a- \5 _3 a& a+ w" i( k0 U2 ]2 ]8 m
- {
+ o0 n9 a; o: q" e0 ^+ ^ - Console.WriteLine("登录失败,请重试。");
9 j1 H) b& K3 @/ {; [ - }
. a( R- I1 {, { y6 u9 o8 a - return o;
8 |4 P5 _3 p( e7 k - }
! T* B1 D7 }: N1 n) X( d
! Q- I! I& {( s0 _: z' W- private static bool ClientLogin(OAuth o)
# D6 s M- K% I) a; a4 g - {0 i, c6 U& Y/ `: H; d; s$ \
- Console.Write("微博账号:");
: u! ~7 R0 {4 i4 g7 S- ~& p - string account = Console.ReadLine();
1 @6 }1 u' b7 X! A$ H2 c7 h g - Console.Write("登录密码:");/ Y1 G1 m+ n3 ?+ O+ d8 S1 q
- ConsoleColor originColor = Console.ForegroundColor;$ J. A6 z( j$ @3 x8 l
- Console.ForegroundColor = Console.BackgroundColor; //知道这里是在干啥不?其实是为了不让你们看到我的密码^_^2 J5 E+ j% P5 h3 M c
- string password = Console.ReadLine();
8 Z. d% X+ }5 a# _# ^# E - Console.ForegroundColor = originColor; //恢复前景颜色。
" Q* }9 _; C$ {! D; B* n* D J - return o.ClientLogin(account, password);
Q5 t# q0 Q" y' r' y) k( U1 l5 J$ G - }/ t/ G/ i$ U ~
- 3 V4 _1 f- B" j5 Q. S
- static void TimerElapsedEvent(object sender, ElapsedEventArgs e)& l* m- Q- o, x4 S# ^
- {" a, _% u& R& ~
- DateTime iNow = DateTime.Now;. H3 l" K& @5 V6 M
- try
7 A) R$ B, s( s" g- f( |) s - {" \- K* c7 H8 s4 ?- q
- string content = makeContent(iNow.Hour, iNow.Minute);) X( g% G0 D' R" J& R
- if (!string.IsNullOrEmpty(content))! Q$ H+ d% O, Y+ O. t6 L5 T
- {
- B# }( j- R7 [ t - var statusInfo = Sina.API.Entity.Statuses.Update(content);2 X/ v& P v$ M* D" [' ~% V6 L1 @
- DateTime dtCreate = DateTime.ParseExact(statusInfo.CreatedAt, "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture);
# w) M, z0 n5 U - Console.WriteLine("本机时间:{0}, 微博时间:{1}, 发布内容:{2}", string.Format("{0:G}", iNow), string.Format("{0:G}", dtCreate), statusInfo.Text);% d3 @* Q' a: S& u$ M
- }
& ^# {7 R/ a* b - }
% F; b; a# x- c1 d! j; n6 R! `* a: G - catch (Exception ex)9 k- N) x2 \- u/ w* X
- {, }5 q: H4 V4 ~, W
- Console.WriteLine("定时任务异常:" + ex.Message);: Y. f$ ] ?) X8 g6 a4 x- o
- }
' `8 x% G) C3 Y! ^. T% e: d1 m - }: z. U( {) K1 G/ X( f+ w
- }" @2 B$ N7 z& g6 B/ q% t0 M
- static string makeContent(int hour24, int minute)/ m* H+ {! P% o- d+ u& }, i# a
- {
$ k+ ]8 T4 v+ X+ a - string[] diZhi = "子|丑|寅|卯|辰|巳|午|未|申|酉|戌|亥".Split('|');
$ ~9 f3 z7 L4 @8 m - string extWeibo = "";
/ a5 v' s; J$ Y U1 d/ M5 P - if (hour24 % 2 == 0 && minute == 0)
R6 s% {. R0 z3 ]/ a& N, h |8 y3 Z - {
1 I+ @7 Y# F6 k$ Q - for (int i = 0; i < ((hour24 >= 12)? (hour24 - 12): hour24); i++)
5 r* B5 Y. b3 v9 X2 c% i - {
: v: ?- p3 B) g) Y8 B' w - extWeibo += "铛~";5 h. W6 V) T) y8 j
- }% N: k; E6 H6 I( m* T
- return "【" + diZhi[hour24 / 2] + "时】" + extWeibo;
" u8 v9 O/ ? u1 r) p. `( u - }
: Y* O6 s. q5 h, f - else1 n7 C& V. d$ }5 x; ]2 ]! O4 G& \8 w$ _
- {1 P/ I( Q9 B4 p( ~8 P) L7 Z. V
- return "";6 x# q6 J! }3 y
- }
7 p) N4 ]9 `( d$ @ - }$ I% y* V" v8 P9 E$ b8 Y" E( o$ J0 u; H
- }) C( g J- {; P, ~/ n* t
- }
复制代码完整程序下载:
) {/ A0 `: j8 G) A |
上一篇:微信支付下一篇:微信公众平台开发(66)人品计算
|