|
大家最近都在热议古城钟楼的红火。不是加V号、不是官方号、不是皇冠会员。没有拟人化,没有段子、没有运营。1天之内从1万不到的粉丝新增了20多万并且还在持续传播和增长粉丝。我不研究它是怎么红起来的,但写个类似的程序实现它却很容易,程序才100行左右: : p6 | j) R" ^, L) i
先来普及一下地支时间与北京时间的对应关系: - 【子时】夜半,又名子夜、中夜:十二时辰的第一个时辰。(北京时间23时至次日01时)。
- 【丑时】鸡鸣,又名荒鸡:十二时辰的第二个时辰。(北京时间01时至03时)。
- 【寅时】平旦,又称黎明、早晨、日旦等:时是夜与日的交替之际。(北京时间03时至05时)。
- 【卯时】日出,又名日始、破晓、旭日等:指太阳刚刚露脸,冉冉初升的那段时间。(北京时间05时至07时)。
- 【辰时】食时,又名早食等:古人“朝食”之时也就是吃早饭时间,(北京时间07时至09时)。
- 【巳时】隅中,又名日禺等:临近中午的时候称为隅中。(北京时间09时至11时)。
- 【午时】日中,又名日正、中午等:(北京时间11时至13时)。
- 【未时】日昳,又名日跌、日央等:太阳偏西为日跌。(北京时间13时至15时)。
- 【申时】哺时,又名日铺、夕食等:(北京时间15时至17时)。
- 【酉时】日入,又名日落、日沉、傍晚:意为太阳落山的时候。(北京时间17时至19时)。
- 【戌时】黄昏,又名日夕、日暮、日晚等:此时太阳已经落山,天将黑未黑。天地昏黄,万物朦胧,故称黄昏。(北京时间19时至21时)。
- 【亥时】人定,又名定昏等:此时夜色已深,人们也已经停止活动,安歇睡眠了。人定也就是人静。(北京时间21时至23时)。$ }/ s1 c: l* ^/ l
) x4 B+ K0 \/ l8 {# I然后我们来分析一下它昨天发布的内容 - 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 【亥时】铛~铛~铛~铛~铛~铛~铛~铛~铛~铛~
4 _# p" g A! P i5 @0 n0 b 6 j% p3 v$ I3 G; v; Q& p7 I5 v& p
根据上面,得出它有以下规律: - 每两个小时发布一条微博,
- 发布时间是偶数小时的0分,这个时间并不是地支时间的开始时间,而是正中间的那个时间点
- 内容是相应的地支时间,加上根据时间而变化的“铛~”的次数,
- “铛~”的次数与时有关,12小时以前与小时相同,12小时以后与[小时减12]相同。
6 l! A) [- ? E' E# j' u
西安钟楼里的钟就是这样敲的吗?去过钟楼一次,没登上去,也没注意。
* b7 h9 k+ M M9 c完整代码如下: 需要自行修改App相关值:
- c9 |1 F6 s. \# Y- : D( r5 L/ R% Z; |4 X+ h5 U% K9 n
- <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;' w3 q6 O4 ]) T* B% k% H
- using System.Collections.Generic;6 L. f1 b2 [, f' Q( ]+ g. G2 S
- using System.Text;5 _3 [$ c) _! j4 i* R0 `
- using NetDimension.Weibo;
; o1 q u [/ @: ?& S' `0 a; A - using System.Timers;* J5 y7 r# h) C7 a& u1 F% U
- using System.Globalization;
, C6 C( B3 _' I
2 D# |+ l# g( w; c- namespace WeiboTimer7 x! s9 S$ S% ?; H3 a
- {6 H* \3 C$ o7 p6 U$ N, P7 i
- class Program. j; U4 B Y- _$ u
- {2 `1 n% \, w( [
- static string AppKey = "********";
6 j7 _. N2 [4 { - static string AppSecret = "*******";/ _) @# W! y2 V6 v9 ^, `& I
- static string CallbackUrl = "****************";
& g7 t3 J" i& d7 f, h i5 t3 d - static Timer t = new Timer();
* Z7 ]. X9 o% W. Z* C - static OAuth oauth = null;
* k, G# Y* N5 E. @2 e- s2 b( l - static Client Sina = null;
3 ?( P! Y6 _) N - 0 t/ N" y) f, J" U; h3 X! F( x4 e }
- static void Main(string[] args). n. p) i3 x: c# ?& Y
- { $ l7 T/ O2 U- q. c0 M
- oauth = Authorize();
! W0 i# k4 d! M - if (!string.IsNullOrEmpty(oauth.AccessToken)){Console.Write("登录成功!");}
" u0 \& k6 m. Q3 _4 `0 }
1 M4 g$ u8 o0 c" [& n( ?2 I1 T- Sina = new Client(oauth);" [+ ^8 ]5 E. R: _) o1 |
- string uid = Sina.API.Entity.Account.GetUID();
9 Z! z6 [3 F4 L; Y; M - var entity_userInfo = Sina.API.Entity.Users.Show(uid);! q' n" d4 L, p% g& t
- Console.WriteLine("昵称:{0},微博地址:http://weibo.com/{1}", entity_userInfo.ScreenName, entity_userInfo.ProfileUrl);& E* t, h# ]2 B+ v
* B/ e% E4 X. ^3 v3 c: \% n; d7 I- try
+ S, w/ t$ o$ b3 f4 V I - {, T- o+ y6 ] ~1 `0 m0 A
- t.Interval = 1000 * 60; //设置间隔时间为1分钟7 L+ Z. O" n5 `9 I1 A
- t.Elapsed += new ElapsedEventHandler(TimerElapsedEvent); //到达时间的时候执行事件;
* Y4 v) v4 a% ~# z* j0 ? - t.AutoReset = true; //设置是执行一次(false)还是一直执行(true);
i/ V" X" s3 j4 W x* s& y - t.Start(); //启动Timer对象; ' b3 f, O( e) b! H& |
- }9 z; \, ]3 u; U4 Q0 n. L
- catch (Exception ex)
: Z) {- [% }% y. B6 P& U y% N - {/ B2 h k' o2 O& |% ?7 V
- Console.WriteLine("定时任务异常:" + ex.Message);! z6 }; R: f' c* J% Y
- t.Stop();
. @* p' I( T% `5 V - }
2 T* t$ t& Y* d% ?+ j3 f0 k$ Z - Console.WriteLine("定时任务开始工作。。。");
1 W; u& z7 j9 H7 S& f3 z6 Q - Console.ReadKey();9 D3 N! Q2 F4 X Q/ ]9 G
- }
. f$ I& \# M) c - - }* H! r5 q% `6 ~6 k/ i% L
- static OAuth Authorize(). Z; \( G2 y4 A+ N$ j8 M1 B9 Q }
- {( |4 d; F% j ?1 X# C
- OAuth o = new OAuth(AppKey, AppSecret, CallbackUrl);
3 M- z1 o9 I* \' C4 F - while (!ClientLogin(o))
: ]. I+ M; @" v9 Z - {
+ @1 F1 W9 n$ }* @% X/ b# G - Console.WriteLine("登录失败,请重试。");! S0 k L4 |* D" `$ f
- }
' J/ I1 [, {$ c ^+ I' N - return o;! |- ^, M. k# Y% d) n2 ^
- }
& R- z' H$ b2 ~+ j - 1 z r, k2 h! r) Y
- private static bool ClientLogin(OAuth o)5 ~! V f2 B- \: s: ?, c1 i- n. `
- {
\ c1 S1 m7 B4 W6 J/ w# _& H - Console.Write("微博账号:");, Z6 A, l' d6 c! \
- string account = Console.ReadLine();' n* L( T% `8 j; _! l
- Console.Write("登录密码:");- N! B2 K! I& Y6 X; y
- ConsoleColor originColor = Console.ForegroundColor;
1 N7 e: }2 j3 e3 e7 I - Console.ForegroundColor = Console.BackgroundColor; //知道这里是在干啥不?其实是为了不让你们看到我的密码^_^
6 X' x5 e+ h9 \9 q( A1 S - string password = Console.ReadLine();
2 T' j( Z! E8 d - Console.ForegroundColor = originColor; //恢复前景颜色。% j( S$ n0 u( R8 L: K
- return o.ClientLogin(account, password);. D6 G$ b5 ?- q6 k
- }
, B- l7 U; v: {9 S+ d K
) M. g1 |: @7 e! _0 t- static void TimerElapsedEvent(object sender, ElapsedEventArgs e)
* ]( K; y- i K6 x% w8 N5 q - {% L, A7 h7 a3 l+ r2 r- g) H
- DateTime iNow = DateTime.Now;% c4 a" o! M; g0 u. R+ J
- try9 _* r+ a1 d' Z( l. q4 s
- {# b. ~& D$ ]( m8 l8 s& \
- string content = makeContent(iNow.Hour, iNow.Minute); Y+ O# I: O) j( S- o1 z
- if (!string.IsNullOrEmpty(content))
' L. a6 U; k: ?* ^+ B7 v1 @% y6 Z - {
, S' K# H' z) j5 I* _# A# l; O( o8 A - var statusInfo = Sina.API.Entity.Statuses.Update(content); x% x8 w. V7 J9 l* s- e$ T" G1 h
- DateTime dtCreate = DateTime.ParseExact(statusInfo.CreatedAt, "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture);( H9 S, k. P; q
- Console.WriteLine("本机时间:{0}, 微博时间:{1}, 发布内容:{2}", string.Format("{0:G}", iNow), string.Format("{0:G}", dtCreate), statusInfo.Text);
! \4 y& ]* B+ x7 [. v2 s - }2 n9 g0 ~# B7 |% Q
- }. k. a3 V; W& H) Z
- catch (Exception ex)$ q `% K) B: e. q. a
- {
: B) O8 f7 P3 s7 ~& M: y4 _- ` - Console.WriteLine("定时任务异常:" + ex.Message);
0 ~* W/ E' g' A$ k - }) n+ g! `1 z5 s' o+ J6 d
- }
8 }* e3 M) W& J0 i' H& d2 B - - D' w& d5 D% ]3 A7 |3 s
- static string makeContent(int hour24, int minute)- N, B& l8 T% C
- {
: k) e2 c1 \$ S6 ~3 `* f. ~ a: M - string[] diZhi = "子|丑|寅|卯|辰|巳|午|未|申|酉|戌|亥".Split('|');
9 ]3 d0 u; R; t4 W - string extWeibo = "";, a+ d7 L4 u* `6 V4 F# e [& ~
- if (hour24 % 2 == 0 && minute == 0)
3 V2 J/ d& P3 Q7 q2 p x - {4 D* D I" S4 X ? x$ Z+ B, y
- for (int i = 0; i < ((hour24 >= 12)? (hour24 - 12): hour24); i++)! j" d$ V& ^% b7 J
- {
0 D5 J9 I7 E5 k* p' ~' I* [ - extWeibo += "铛~";3 Z: v8 l' h o* Q ?* M
- }, p% E4 e, Y5 o( y/ ?- Q: p3 t: e. {
- return "【" + diZhi[hour24 / 2] + "时】" + extWeibo;" c d m3 x( E1 L; l$ j
- }- @. H5 p% s7 y& r
- else% T: I$ X3 v+ w
- {' e: x1 n9 d2 [% K
- return "";* h; q9 G0 e/ C! X0 J8 g" b
- }8 B8 }3 F7 w% w
- }0 L! p# C$ H5 ] d6 u
- }2 o# k0 l6 O0 x6 d$ b
- }
复制代码完整程序下载:
( x; Y& N2 c- a+ x" q5 Z0 d |
上一篇:微信支付下一篇:微信公众平台开发(66)人品计算
|