大家最近都在热议古城钟楼的红火。不是加V号、不是官方号、不是皇冠会员。没有拟人化,没有段子、没有运营。1天之内从1万不到的粉丝新增了20多万并且还在持续传播和增长粉丝。我不研究它是怎么红起来的,但写个类似的程序实现它却很容易,程序才100行左右: 8 P& c" y' E! E- T, y8 P
先来普及一下地支时间与北京时间的对应关系: - 【子时】夜半,又名子夜、中夜:十二时辰的第一个时辰。(北京时间23时至次日01时)。
- 【丑时】鸡鸣,又名荒鸡:十二时辰的第二个时辰。(北京时间01时至03时)。
- 【寅时】平旦,又称黎明、早晨、日旦等:时是夜与日的交替之际。(北京时间03时至05时)。
- 【卯时】日出,又名日始、破晓、旭日等:指太阳刚刚露脸,冉冉初升的那段时间。(北京时间05时至07时)。
- 【辰时】食时,又名早食等:古人“朝食”之时也就是吃早饭时间,(北京时间07时至09时)。
- 【巳时】隅中,又名日禺等:临近中午的时候称为隅中。(北京时间09时至11时)。
- 【午时】日中,又名日正、中午等:(北京时间11时至13时)。
- 【未时】日昳,又名日跌、日央等:太阳偏西为日跌。(北京时间13时至15时)。
- 【申时】哺时,又名日铺、夕食等:(北京时间15时至17时)。
- 【酉时】日入,又名日落、日沉、傍晚:意为太阳落山的时候。(北京时间17时至19时)。
- 【戌时】黄昏,又名日夕、日暮、日晚等:此时太阳已经落山,天将黑未黑。天地昏黄,万物朦胧,故称黄昏。(北京时间19时至21时)。
- 【亥时】人定,又名定昏等:此时夜色已深,人们也已经停止活动,安歇睡眠了。人定也就是人静。(北京时间21时至23时)。
1 a* Y: o% \8 T1 \9 p 1 C; O( [$ V ]- c/ J
然后我们来分析一下它昨天发布的内容 - 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 P/ j- ]2 M/ m# W# C( e7 f
( g" q) R8 m! M. O3 H
根据上面,得出它有以下规律: - 每两个小时发布一条微博,
- 发布时间是偶数小时的0分,这个时间并不是地支时间的开始时间,而是正中间的那个时间点
- 内容是相应的地支时间,加上根据时间而变化的“铛~”的次数,
- “铛~”的次数与时有关,12小时以前与小时相同,12小时以后与[小时减12]相同。1 s9 w9 U+ E4 b7 g. `) l" S, Q
西安钟楼里的钟就是这样敲的吗?去过钟楼一次,没登上去,也没注意。
j$ D7 j% L5 y+ K, f. T0 S完整代码如下: 需要自行修改App相关值: 3 }7 k' J- x0 C! p
" g9 Y& e8 x% U: d w: r4 \: y P- <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;; ?: u2 ]8 _9 x" a% v; K
- using System.Collections.Generic;$ N/ Y! s3 f7 O1 y7 U$ }9 j
- using System.Text;! ]$ y) R# [* |. N I
- using NetDimension.Weibo;5 G; P0 ?( h* z& p$ _' \0 X
- using System.Timers;5 i; \* f U2 X+ s$ V% d
- using System.Globalization;
2 ]$ Z& d0 u/ [
$ N' o' i; I8 b6 l0 H# @2 p/ o& E- namespace WeiboTimer- B3 v* ~: W' j f. }0 ^
- {6 f% v- O8 _. Y* F* |
- class Program6 o, F. C! I/ ]5 y3 ?7 @; a+ N
- {
8 X, v; p' o( ` - static string AppKey = "********";
6 y, E2 }3 Q* w - static string AppSecret = "*******";
4 ~, J i/ s" S, Z* K- h' q; `/ Z - static string CallbackUrl = "****************";: `% d' _3 T' U* a7 k" V) X
- static Timer t = new Timer(); m1 L2 \) V+ E2 P% {
- static OAuth oauth = null;* z% X( E3 _9 X: r
- static Client Sina = null;6 Y, H. F7 I4 ~& @# S( V: J, u
- s1 {3 C* N- v
- static void Main(string[] args)
4 Z) Q9 X8 I8 Z i' z - { ( S& I/ ~( D" E8 `( y- E$ V! T
- oauth = Authorize();- o7 O. ~0 ~" D
- if (!string.IsNullOrEmpty(oauth.AccessToken)){Console.Write("登录成功!");}
% U3 R2 J! P" C. a2 C
6 e2 y/ k& V# I! u% {. t- Sina = new Client(oauth);
* ]+ r6 p8 C$ n& Q: X - string uid = Sina.API.Entity.Account.GetUID();4 ?5 l8 ]- W9 Q0 ` v
- var entity_userInfo = Sina.API.Entity.Users.Show(uid);) p* \. o2 F7 K, }. h E) D0 ]3 u
- Console.WriteLine("昵称:{0},微博地址:http://weibo.com/{1}", entity_userInfo.ScreenName, entity_userInfo.ProfileUrl);
# X3 e; V6 n) w5 D% R - 9 y5 e9 w3 K8 O h* p3 p) y
- try0 j0 n; t k" Q) c; |; X: h$ x
- {- z S, O" H+ e
- t.Interval = 1000 * 60; //设置间隔时间为1分钟
! i5 Z: J* W U' t! ~! N - t.Elapsed += new ElapsedEventHandler(TimerElapsedEvent); //到达时间的时候执行事件;
# U* M2 F& s f. b f- Z - t.AutoReset = true; //设置是执行一次(false)还是一直执行(true);
5 v$ C5 `8 w# f- f! P - t.Start(); //启动Timer对象; # [2 g: P/ A6 P& z1 @
- }
# E! W; }2 h s- _. b - catch (Exception ex)+ z4 x0 V7 G+ S" N, E6 b* n2 T& z
- {3 O+ ?! z/ T) v6 U' Y% g9 |
- Console.WriteLine("定时任务异常:" + ex.Message);
: j! j2 p% u* b7 H- [* B - t.Stop();# h; v6 X$ P, E2 `1 ]& l Q; O
- }' s* \3 J/ g5 d- ^) i% H
- Console.WriteLine("定时任务开始工作。。。");
& ^/ i; W! N _ - Console.ReadKey();
% ?! n0 g& p& h, t1 T6 f - }+ {9 ~+ A) R* Z2 ]
8 |& Z1 }* l- _- static OAuth Authorize()/ A; z5 P9 K. {
- {9 W9 l+ f0 M- B' x3 I/ V J2 Y& C' g8 N
- OAuth o = new OAuth(AppKey, AppSecret, CallbackUrl);
' H; k& K+ B! R6 y+ x9 G3 O' U - while (!ClientLogin(o))
) x+ M' w- r1 F% F, }- W - {
. O/ F, L+ L: q$ a8 Q - Console.WriteLine("登录失败,请重试。");
0 ?- }+ a8 h- s! c; L* P! _ - }4 T5 R3 P" Q+ _' E Y& f
- return o;* I" T# K3 S% d2 O, A6 A
- }
2 d- @9 b( T- m' L) \ z4 q6 e5 p - : l8 R; Z) E4 Z4 F) E" x
- private static bool ClientLogin(OAuth o)
) H3 o( ~! {( | - {; q8 F: ]0 d1 ]) v2 P
- Console.Write("微博账号:");- D" }+ C6 e: U) E' b0 U
- string account = Console.ReadLine();
# v2 t. v/ h9 \9 K5 o - Console.Write("登录密码:");* f. F% {3 K4 \3 m" \" S9 `
- ConsoleColor originColor = Console.ForegroundColor;
$ e$ C) f: ?: Z1 H2 c) ?; a - Console.ForegroundColor = Console.BackgroundColor; //知道这里是在干啥不?其实是为了不让你们看到我的密码^_^4 F: ~5 _: ^; {- B- o" Y0 V
- string password = Console.ReadLine();5 R* A J- s7 P
- Console.ForegroundColor = originColor; //恢复前景颜色。# X4 L' C3 w T% N) ~6 `/ ]2 N
- return o.ClientLogin(account, password);
3 Q# ^8 ]* W( k. q - }: M- G& k4 `- p. M# y. d, b: {0 E
- 0 R* d3 y6 ~3 m; J; o5 d' @ }8 y
- static void TimerElapsedEvent(object sender, ElapsedEventArgs e)
9 y1 m. z5 @% e B- F9 i - {1 t$ p2 Z, G' _+ h! r. E
- DateTime iNow = DateTime.Now; O$ l2 d( P9 `( c$ f
- try( y2 _3 {0 |3 @' m; f
- {- l/ {/ f8 c) N! ]) D- m
- string content = makeContent(iNow.Hour, iNow.Minute);
- X( r: e' {6 l& M4 q3 l( O - if (!string.IsNullOrEmpty(content))
9 L3 i) ^5 @, W; T1 c( [ - {
2 k8 z8 u% d6 F/ k+ Z( s - var statusInfo = Sina.API.Entity.Statuses.Update(content);
5 _/ Q4 N. d, E3 w - DateTime dtCreate = DateTime.ParseExact(statusInfo.CreatedAt, "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture);, W1 ?9 l6 u) L& \% M4 a
- Console.WriteLine("本机时间:{0}, 微博时间:{1}, 发布内容:{2}", string.Format("{0:G}", iNow), string.Format("{0:G}", dtCreate), statusInfo.Text);
( y4 ?+ `: k2 ^- }3 |9 k- A& y3 X3 S) h - }
! Y7 s; ^2 e* m) _8 E - }
8 k5 J: t( b) m& e0 m - catch (Exception ex)
' c: }8 |% r1 R2 Y1 Z - {
5 V' S2 b, a, u0 Q" S) _ - Console.WriteLine("定时任务异常:" + ex.Message);! W$ k% X: {' ^ l$ Z
- }7 u+ L( X a G0 U
- }/ r: ~3 h7 O. W% h: U. T
- 7 W! \( K9 a, E g
- static string makeContent(int hour24, int minute)
7 E: e5 x$ X$ H/ Q- y* c% v - {; ?1 y) t% \5 { Q& a
- string[] diZhi = "子|丑|寅|卯|辰|巳|午|未|申|酉|戌|亥".Split('|');; K# h) q; W4 D- A# s; j! Y
- string extWeibo = "";
5 B5 g7 T' @1 M - if (hour24 % 2 == 0 && minute == 0)1 x, _/ \. `" G3 p' E9 V; |
- {
8 A2 Z! B+ v' Y/ w$ i3 r: ? - for (int i = 0; i < ((hour24 >= 12)? (hour24 - 12): hour24); i++)% I: ?* c! V; ]" U. x
- {
; C2 o# B; v+ y% I7 c% F4 N& H - extWeibo += "铛~";
. W# T, f- ]! p" z8 C& U/ l; [% N; } - }& x# e) k) `, P% u( p5 `& \( X% j
- return "【" + diZhi[hour24 / 2] + "时】" + extWeibo;
* ]& U7 g% d3 ^; z - }
( D7 W8 X' h h5 |: n5 t7 @) W - else/ L' F. E8 `3 H! ~
- {0 _ I" o, J$ j2 x) e ?6 c3 e
- return "";2 [( {( E+ T7 N' t c; F1 c. G" k0 k- y
- } H# T9 K4 V- m, m
- }% k# _9 W2 |7 @; h' w7 d
- }# I0 r( B B/ R0 R/ @$ i
- }
复制代码完整程序下载:
4 I( k2 K1 |; G5 V) |$ L8 c+ @ |
上一篇:微信支付下一篇:微信公众平台开发(66)人品计算
|