|
大家最近都在热议古城钟楼的红火。不是加V号、不是官方号、不是皇冠会员。没有拟人化,没有段子、没有运营。1天之内从1万不到的粉丝新增了20多万并且还在持续传播和增长粉丝。我不研究它是怎么红起来的,但写个类似的程序实现它却很容易,程序才100行左右: . W+ M4 C% I0 g. r* Q) `; L
先来普及一下地支时间与北京时间的对应关系: - 【子时】夜半,又名子夜、中夜:十二时辰的第一个时辰。(北京时间23时至次日01时)。
- 【丑时】鸡鸣,又名荒鸡:十二时辰的第二个时辰。(北京时间01时至03时)。
- 【寅时】平旦,又称黎明、早晨、日旦等:时是夜与日的交替之际。(北京时间03时至05时)。
- 【卯时】日出,又名日始、破晓、旭日等:指太阳刚刚露脸,冉冉初升的那段时间。(北京时间05时至07时)。
- 【辰时】食时,又名早食等:古人“朝食”之时也就是吃早饭时间,(北京时间07时至09时)。
- 【巳时】隅中,又名日禺等:临近中午的时候称为隅中。(北京时间09时至11时)。
- 【午时】日中,又名日正、中午等:(北京时间11时至13时)。
- 【未时】日昳,又名日跌、日央等:太阳偏西为日跌。(北京时间13时至15时)。
- 【申时】哺时,又名日铺、夕食等:(北京时间15时至17时)。
- 【酉时】日入,又名日落、日沉、傍晚:意为太阳落山的时候。(北京时间17时至19时)。
- 【戌时】黄昏,又名日夕、日暮、日晚等:此时太阳已经落山,天将黑未黑。天地昏黄,万物朦胧,故称黄昏。(北京时间19时至21时)。
- 【亥时】人定,又名定昏等:此时夜色已深,人们也已经停止活动,安歇睡眠了。人定也就是人静。(北京时间21时至23时)。' @ {7 _; l9 c% \8 o% V) h6 E
% L$ w3 e$ J, \4 c; t) F0 q然后我们来分析一下它昨天发布的内容 - 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 B" t9 R# b7 |" c* D( }
- \# L7 s% x( Z1 ^: u0 ?, o( S根据上面,得出它有以下规律: - 每两个小时发布一条微博,
- 发布时间是偶数小时的0分,这个时间并不是地支时间的开始时间,而是正中间的那个时间点
- 内容是相应的地支时间,加上根据时间而变化的“铛~”的次数,
- “铛~”的次数与时有关,12小时以前与小时相同,12小时以后与[小时减12]相同。; v# s( T' {# x1 W3 C5 r
西安钟楼里的钟就是这样敲的吗?去过钟楼一次,没登上去,也没注意。 & v3 a2 f# K7 Z( Y! L3 D7 W' t' A
完整代码如下: 需要自行修改App相关值:
7 P" L, B+ p+ Q1 a$ i" V1 u$ V
( {: d& n1 H/ C& E4 T/ a6 B- <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;
C' P5 E: Q: U, v - using System.Collections.Generic;
# T: M6 J: |( U, q3 o, f% U - using System.Text;: I. t8 r8 D9 Q- p, u0 z; D2 T) c8 t
- using NetDimension.Weibo;0 j4 G v. {& ]& U; e
- using System.Timers;
9 w; h: ?; n6 N8 y% o" r/ \6 Z - using System.Globalization;* [1 l( |# M0 Z b7 y
- m% g3 U! O, [/ f" ^- namespace WeiboTimer
5 n4 N9 n8 `3 [! V - {
" K: O$ S; X* r2 r* Y4 o- s - class Program2 c6 u' G* l0 B( Z0 \6 R
- {. P Y" Y5 e1 P* {. V8 H0 |$ \
- static string AppKey = "********";
+ U. ]* E$ ^' w4 \* i$ o - static string AppSecret = "*******";
) y# t6 Z$ O9 Q# t9 v* Z - static string CallbackUrl = "****************";8 B, N. z$ `" p; B+ v7 J2 S
- static Timer t = new Timer();; f8 j" i4 e; e) H# Q9 q
- static OAuth oauth = null;
8 F- y; Y& j4 m2 z - static Client Sina = null;5 o( I4 @% Y4 M# `
- 7 |: i+ E$ s+ M+ n2 K V1 e! `' I2 ~
- static void Main(string[] args)0 |+ P5 @1 h2 G, w8 Z- ?5 K: q
- {
6 W) c" L, T. z- i - oauth = Authorize();
) N+ x. W0 _: T# _2 H! w+ y8 ` - if (!string.IsNullOrEmpty(oauth.AccessToken)){Console.Write("登录成功!");}
3 ^' D" h( E6 Y - . G( ~8 |" L' [. n9 o+ P1 O# [2 @
- Sina = new Client(oauth);
5 v, h& `/ z4 j+ ?4 x( ]$ N3 f - string uid = Sina.API.Entity.Account.GetUID();/ E9 C2 S4 r7 M) d3 B" H; e2 K: }. R. E
- var entity_userInfo = Sina.API.Entity.Users.Show(uid); w+ f0 ?) e! \( N2 n: P4 X
- Console.WriteLine("昵称:{0},微博地址:http://weibo.com/{1}", entity_userInfo.ScreenName, entity_userInfo.ProfileUrl);
% f: s9 R4 m0 z3 N/ e! U9 ^ - . T& z o: g$ R' n# X/ [7 V
- try2 c! t" j# q7 D D$ c7 q- b
- {
5 A* F5 o: l" [ - t.Interval = 1000 * 60; //设置间隔时间为1分钟* E' J& c' Y. G- y% |
- t.Elapsed += new ElapsedEventHandler(TimerElapsedEvent); //到达时间的时候执行事件;
, ^! L% K9 n( x: x - t.AutoReset = true; //设置是执行一次(false)还是一直执行(true);
{+ ]( e; l8 u( I$ h - t.Start(); //启动Timer对象; S1 T6 O- P" |% j+ r. [$ x
- }9 P/ z, T/ ^( f# E
- catch (Exception ex)& N. H2 B1 g4 |
- {8 c9 `. W4 l5 ^$ c1 K4 K7 d
- Console.WriteLine("定时任务异常:" + ex.Message);
1 V+ i2 I J9 B2 C" i' m, n - t.Stop();
z- R- D% P, K) i9 ]2 ? - }- B" s4 A2 X3 T) J- J1 G
- Console.WriteLine("定时任务开始工作。。。");' m7 L. Y5 o2 H
- Console.ReadKey();
+ p- {- [& R: J I/ P$ G8 p - }: x: n/ r( e7 g, U, ]
- e7 j+ @3 M% R8 K* Q
- static OAuth Authorize()
& w! P( i" P. ~" |' y1 @ - {
* ?7 D! O: @- t6 R% ?$ s! _ - OAuth o = new OAuth(AppKey, AppSecret, CallbackUrl);. W- S" Z( D% f
- while (!ClientLogin(o))) g8 u+ Z2 N, w+ W
- {
) v. u) } D: X8 d4 h8 k# J7 W - Console.WriteLine("登录失败,请重试。");" K6 l, W' r. ^
- }
! r) V; u) s9 |" S' q - return o;
$ o3 m z U. [7 | - }
7 c* Y" |% q2 d3 n Y
1 [3 `# g* Z: K* y" M" l- private static bool ClientLogin(OAuth o). r$ Y& G; {: P% Z5 p3 `+ O
- {8 b" x9 B4 D7 k a
- Console.Write("微博账号:");
! I5 Q: A& Z1 a7 D9 R$ M! _ - string account = Console.ReadLine();1 ]" l8 e/ `: p: _5 k
- Console.Write("登录密码:");
/ m5 }* |' V6 `+ t# m7 D- | - ConsoleColor originColor = Console.ForegroundColor;
9 Q; \9 M0 w9 j9 i7 l3 @ - Console.ForegroundColor = Console.BackgroundColor; //知道这里是在干啥不?其实是为了不让你们看到我的密码^_^7 q1 q, s( p3 t2 V) @; i4 ?
- string password = Console.ReadLine();
7 S) C' b" q) A8 ` - Console.ForegroundColor = originColor; //恢复前景颜色。
4 t" M) n' _1 [2 ~ - return o.ClientLogin(account, password);- u. K8 ?1 f8 h
- }4 L x. F1 X2 x7 P. p
( t* n4 X3 L8 o; b ~- static void TimerElapsedEvent(object sender, ElapsedEventArgs e)
1 X7 W& e3 }+ m: d% w% Y( N - {1 Z: E! W! n4 Z# D, k4 J
- DateTime iNow = DateTime.Now;; n7 n" Z9 A+ s
- try
+ B) p/ Y, I* W! P! x1 a4 f - {
' |) o, [( c" t7 N) X6 \ - string content = makeContent(iNow.Hour, iNow.Minute);
, v! m z0 `9 ~7 S i" r' h - if (!string.IsNullOrEmpty(content))6 U) d) S2 E6 {) ^' J1 ~
- {: R' |5 j5 ^7 B2 N! \: z
- var statusInfo = Sina.API.Entity.Statuses.Update(content);$ t: C a" S i7 U$ h. r3 T
- DateTime dtCreate = DateTime.ParseExact(statusInfo.CreatedAt, "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture);3 t& A1 A z" B+ s; t% d3 L
- Console.WriteLine("本机时间:{0}, 微博时间:{1}, 发布内容:{2}", string.Format("{0:G}", iNow), string.Format("{0:G}", dtCreate), statusInfo.Text);
1 J3 [0 B5 ^* D+ |% a; o- } - }2 H/ |, V9 L# w+ [. Q: d( f' i
- }/ A3 e8 m) }2 ?4 I
- catch (Exception ex)
" u8 h" o3 Q8 p9 |4 B8 s" K, w - {- t2 q5 p- T6 K" Q
- Console.WriteLine("定时任务异常:" + ex.Message);
9 c: e& L; F2 c1 F - }
# s( z8 l8 u' d+ ?+ K# t - }
4 I) V. z+ Z& ]9 F$ g7 [7 l - 2 t0 _" W. ~ u5 \2 `* \! h: @. M
- static string makeContent(int hour24, int minute)2 ?- V6 _6 h4 A- `8 \6 i
- {
1 Z% j/ P& @! {6 M* | - string[] diZhi = "子|丑|寅|卯|辰|巳|午|未|申|酉|戌|亥".Split('|');7 X/ o. J0 Z/ k9 M s4 M( Q
- string extWeibo = "";; ]0 r* B( |4 M0 V0 w
- if (hour24 % 2 == 0 && minute == 0); G& d7 E ?; h0 g
- {
+ e" L: o2 X9 I( u; s - for (int i = 0; i < ((hour24 >= 12)? (hour24 - 12): hour24); i++)9 c0 N* Q0 u: h" c
- {
0 H+ B0 Q. s7 F, R& [0 Y& D0 @ - extWeibo += "铛~";; J, ?# h% q$ o5 z
- } O) O; m1 ~' D) h& i
- return "【" + diZhi[hour24 / 2] + "时】" + extWeibo;
* y. L$ r! G2 ?3 x/ {! Z - }
: D5 |4 s& S. T8 I$ M - else# u3 E% ?0 O- _6 c) l8 h5 @
- {8 K) |( Y3 i# R8 S
- return "";6 U& C7 h% E# b K
- }7 w' l* i6 S8 U" O' B* ~
- }" g0 C8 ?% I7 X; b) l2 F
- }
" M. k4 Q6 H/ [4 m5 P) ?7 [ - }
复制代码完整程序下载: , q* E( |0 a2 K. v% A
|
上一篇:微信支付下一篇:微信公众平台开发(66)人品计算
|