大家最近都在热议古城钟楼的红火。不是加V号、不是官方号、不是皇冠会员。没有拟人化,没有段子、没有运营。1天之内从1万不到的粉丝新增了20多万并且还在持续传播和增长粉丝。我不研究它是怎么红起来的,但写个类似的程序实现它却很容易,程序才100行左右:
* p. ^* r3 o3 T s7 {: U9 s7 G先来普及一下地支时间与北京时间的对应关系: - 【子时】夜半,又名子夜、中夜:十二时辰的第一个时辰。(北京时间23时至次日01时)。
- 【丑时】鸡鸣,又名荒鸡:十二时辰的第二个时辰。(北京时间01时至03时)。
- 【寅时】平旦,又称黎明、早晨、日旦等:时是夜与日的交替之际。(北京时间03时至05时)。
- 【卯时】日出,又名日始、破晓、旭日等:指太阳刚刚露脸,冉冉初升的那段时间。(北京时间05时至07时)。
- 【辰时】食时,又名早食等:古人“朝食”之时也就是吃早饭时间,(北京时间07时至09时)。
- 【巳时】隅中,又名日禺等:临近中午的时候称为隅中。(北京时间09时至11时)。
- 【午时】日中,又名日正、中午等:(北京时间11时至13时)。
- 【未时】日昳,又名日跌、日央等:太阳偏西为日跌。(北京时间13时至15时)。
- 【申时】哺时,又名日铺、夕食等:(北京时间15时至17时)。
- 【酉时】日入,又名日落、日沉、傍晚:意为太阳落山的时候。(北京时间17时至19时)。
- 【戌时】黄昏,又名日夕、日暮、日晚等:此时太阳已经落山,天将黑未黑。天地昏黄,万物朦胧,故称黄昏。(北京时间19时至21时)。
- 【亥时】人定,又名定昏等:此时夜色已深,人们也已经停止活动,安歇睡眠了。人定也就是人静。(北京时间21时至23时)。$ _# Z8 T. g, R6 t, L) h6 I% y
: y4 \/ ~/ i1 g: f6 l$ x2 ^然后我们来分析一下它昨天发布的内容 - 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 【亥时】铛~铛~铛~铛~铛~铛~铛~铛~铛~铛~7 x! X2 U8 T3 m
$ m4 a/ ?( r2 b- p- \: c9 T* Z7 p根据上面,得出它有以下规律: - 每两个小时发布一条微博,
- 发布时间是偶数小时的0分,这个时间并不是地支时间的开始时间,而是正中间的那个时间点
- 内容是相应的地支时间,加上根据时间而变化的“铛~”的次数,
- “铛~”的次数与时有关,12小时以前与小时相同,12小时以后与[小时减12]相同。
5 e3 i( w% g4 X- F
西安钟楼里的钟就是这样敲的吗?去过钟楼一次,没登上去,也没注意。
% k$ t; I0 E* l: C- ]# j. c" V完整代码如下: 需要自行修改App相关值:
4 V6 |& ~5 `/ ~7 Z! r' M# y3 u- 1 r6 K1 k5 Q n3 ^
- <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;. v! U/ C9 }3 K; K+ R. _& U6 b& H
- using System.Collections.Generic;1 ]" D6 W* D, g
- using System.Text;! }% a6 E9 z! `& O3 H
- using NetDimension.Weibo;: T- Y( m7 I" L& j
- using System.Timers;
+ C$ h9 q/ f% V, p+ L2 B - using System.Globalization;
* }+ T8 I0 D! C$ B* X8 w
0 c. S4 U5 g" Z6 \- namespace WeiboTimer
9 @5 k; a- T1 A0 E' [ J - {2 T" J0 t0 F- j* l& d
- class Program
; s) {/ g: w/ M r - {
1 f: J. K9 M. k5 p3 v! A - static string AppKey = "********";
+ p" d1 r9 I, {1 M& J - static string AppSecret = "*******";
; K b7 l. v( h( m% l, T - static string CallbackUrl = "****************";
% e6 V2 s6 N1 } u- l/ P4 Z - static Timer t = new Timer();% |( R# G2 _6 s7 Z& S( v
- static OAuth oauth = null;$ G. g+ R8 G3 S/ J) R& Y6 o
- static Client Sina = null;
$ _9 u! m' t, M* U8 K
# s+ ^( B0 ?2 ?2 O0 x9 [( d- static void Main(string[] args)
* {0 z" }6 A ~+ I6 E+ ]- W& l0 v - {
7 ^ p" K& Y( _7 P( M$ m5 e; k - oauth = Authorize();
- s/ y$ _" u7 l) F% e* Q8 G6 _' A - if (!string.IsNullOrEmpty(oauth.AccessToken)){Console.Write("登录成功!");}
( a# v# B# S5 `3 i; J3 K - ! D6 |+ G5 R& D% p4 K/ ]
- Sina = new Client(oauth);2 y) E. a& q$ v9 D3 b! u1 u
- string uid = Sina.API.Entity.Account.GetUID();4 c w! A& |5 G5 @; h* |
- var entity_userInfo = Sina.API.Entity.Users.Show(uid);# ~9 h) Q: R0 n. V. J3 K
- Console.WriteLine("昵称:{0},微博地址:http://weibo.com/{1}", entity_userInfo.ScreenName, entity_userInfo.ProfileUrl); V$ H" W6 A4 h7 |' X8 Q! ?
$ {5 O. i! o, [- try2 h2 k: g7 L: n/ ~* P, | Q# a
- {
. i: I- V1 A" [- | - t.Interval = 1000 * 60; //设置间隔时间为1分钟
- W+ R* T) q1 B/ y - t.Elapsed += new ElapsedEventHandler(TimerElapsedEvent); //到达时间的时候执行事件; % E) a" N& z( g+ Q
- t.AutoReset = true; //设置是执行一次(false)还是一直执行(true);
4 l2 y- s$ h' u+ N# D1 M% K - t.Start(); //启动Timer对象; 3 [+ L6 |. F3 b- ?- K, A4 a
- }0 J9 g: _2 }* ?3 g7 M, c
- catch (Exception ex)
( y5 `9 J9 G* [( g1 ? - {
2 S$ e3 e* h; _/ I - Console.WriteLine("定时任务异常:" + ex.Message);
# l: F: j, Y) K2 y4 a; U! [4 u - t.Stop();
+ j2 j: p; _- ?6 z( R0 M( h7 [3 O1 l( k - }6 Z3 z" C/ N% L7 D7 X8 c
- Console.WriteLine("定时任务开始工作。。。");
. m# m+ n- k' a: n, K - Console.ReadKey();+ }' U0 ~3 O* t0 b$ C# l/ ?
- }
- A( x# T. e/ {: W& p% a
, @2 c& r' f% l3 ^) o- static OAuth Authorize(), j8 t: | t" ~: L9 P6 x/ g
- {
; g1 r1 W) t R: H3 I - OAuth o = new OAuth(AppKey, AppSecret, CallbackUrl);- }6 G, Q- a5 }, k
- while (!ClientLogin(o))
3 k# J. z6 z& T; E g+ v5 w - {
0 a+ s: d: D+ g - Console.WriteLine("登录失败,请重试。");
+ Q* u' o4 F4 o/ |) Y - }5 P1 M* f7 g# n4 w; A! B
- return o;
7 s0 i: E8 \0 O! T' {/ j - }
1 d- ^ A' n$ i: @; B2 l ^
9 }/ [4 A( R) w7 `! r- private static bool ClientLogin(OAuth o)
' K- v6 k X( v2 s - {
* A1 ~- h7 |# K" f0 w - Console.Write("微博账号:");3 b& m- U- f6 x* H. {4 m# O/ D
- string account = Console.ReadLine();5 v+ g7 b* ]+ M b! t3 ?* t
- Console.Write("登录密码:");& y/ s) ?6 `) C0 \4 k2 c
- ConsoleColor originColor = Console.ForegroundColor;" K( R. g2 D& }0 ~1 I+ u) G
- Console.ForegroundColor = Console.BackgroundColor; //知道这里是在干啥不?其实是为了不让你们看到我的密码^_^
1 z! Z$ n2 b0 k3 @2 @; j( U, a - string password = Console.ReadLine();
7 D$ H8 H: ~4 Y5 V/ A - Console.ForegroundColor = originColor; //恢复前景颜色。. h. M% q" ^& ~* a5 u6 ]* I! ]
- return o.ClientLogin(account, password);
" b/ Q0 z( C$ E5 Q - }: }; f& c5 o. u: R D( V; F
- * z! R8 y2 S5 }5 A' {
- static void TimerElapsedEvent(object sender, ElapsedEventArgs e)
9 Q! |/ a T: p. H3 } - {
& m" m$ G& M9 n+ k3 q& S: v - DateTime iNow = DateTime.Now;
6 j! k* T) r* ~% b% _4 a8 l4 b - try
. s) s8 @2 o9 F3 f" X - {
5 F, D4 q. o) e; [ - string content = makeContent(iNow.Hour, iNow.Minute);1 h. g* S h+ @
- if (!string.IsNullOrEmpty(content))
$ Z# I+ [, [8 b0 x/ F2 t& m" y - {! a B# Q* S1 h9 Z& c& ]% D# N% n
- var statusInfo = Sina.API.Entity.Statuses.Update(content);
4 l: ^% Y6 {6 p: x' J+ o; [9 q - DateTime dtCreate = DateTime.ParseExact(statusInfo.CreatedAt, "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture);% |0 [6 _& h& ~. _! V. y
- Console.WriteLine("本机时间:{0}, 微博时间:{1}, 发布内容:{2}", string.Format("{0:G}", iNow), string.Format("{0:G}", dtCreate), statusInfo.Text);
2 S# p. P# v' k/ c( Y* p6 s& L - }' b4 _% V8 c% s- w
- }; |2 |0 b& |8 s; H) ]0 L( s5 ^
- catch (Exception ex), U# e# O, [( @3 X" w, X' h
- {/ D6 J { B7 m' p8 n8 v
- Console.WriteLine("定时任务异常:" + ex.Message);7 Q; x/ z% w2 E9 u: M
- }5 w7 C6 @: z- ~+ A8 ]3 q* n
- }2 V3 [* N3 z: T+ u6 ?
- + Q0 g5 T |; n/ ?5 ~$ |8 p, n1 E: f
- static string makeContent(int hour24, int minute)
! U; _, ^& A" T* d6 E' D2 @ - {. O. V. c5 r/ X. g6 l! ?- T1 }/ B- m; l
- string[] diZhi = "子|丑|寅|卯|辰|巳|午|未|申|酉|戌|亥".Split('|');4 R. [, S2 }' q* S" w
- string extWeibo = "";- @$ O! ]5 j; P" @4 Y/ E* J# T8 M \
- if (hour24 % 2 == 0 && minute == 0)% }8 h" n9 V* V' p. o
- {
; [: d) ?6 _2 C# b& v - for (int i = 0; i < ((hour24 >= 12)? (hour24 - 12): hour24); i++)
6 ^& `* [0 u. T7 T" u - {
! y1 ~# a! j9 l8 \6 H - extWeibo += "铛~";5 [* @+ X, h2 Q6 p( E
- }
, F) u, z$ I& F* ~% {+ ] - return "【" + diZhi[hour24 / 2] + "时】" + extWeibo;4 K& H, Z1 P: d4 G
- }
E# X9 W9 [8 Y - else
8 J' X) a- O9 }9 u9 u - {) U: y( K/ J! f4 W- a- O
- return "";. C6 F' F7 Y+ j4 J
- }$ \% e" R k. H9 C6 P
- }
8 w0 {% Q6 R6 t! d" A( f! L - }
; y+ J6 P6 v/ m" O - }
复制代码完整程序下载:
" Q& P" j$ k, W2 F5 x |
上一篇:微信支付下一篇:微信公众平台开发(66)人品计算
|