|
大家最近都在热议古城钟楼的红火。不是加V号、不是官方号、不是皇冠会员。没有拟人化,没有段子、没有运营。1天之内从1万不到的粉丝新增了20多万并且还在持续传播和增长粉丝。我不研究它是怎么红起来的,但写个类似的程序实现它却很容易,程序才100行左右:
' |! ~( o' K4 d' }6 |先来普及一下地支时间与北京时间的对应关系: - 【子时】夜半,又名子夜、中夜:十二时辰的第一个时辰。(北京时间23时至次日01时)。
- 【丑时】鸡鸣,又名荒鸡:十二时辰的第二个时辰。(北京时间01时至03时)。
- 【寅时】平旦,又称黎明、早晨、日旦等:时是夜与日的交替之际。(北京时间03时至05时)。
- 【卯时】日出,又名日始、破晓、旭日等:指太阳刚刚露脸,冉冉初升的那段时间。(北京时间05时至07时)。
- 【辰时】食时,又名早食等:古人“朝食”之时也就是吃早饭时间,(北京时间07时至09时)。
- 【巳时】隅中,又名日禺等:临近中午的时候称为隅中。(北京时间09时至11时)。
- 【午时】日中,又名日正、中午等:(北京时间11时至13时)。
- 【未时】日昳,又名日跌、日央等:太阳偏西为日跌。(北京时间13时至15时)。
- 【申时】哺时,又名日铺、夕食等:(北京时间15时至17时)。
- 【酉时】日入,又名日落、日沉、傍晚:意为太阳落山的时候。(北京时间17时至19时)。
- 【戌时】黄昏,又名日夕、日暮、日晚等:此时太阳已经落山,天将黑未黑。天地昏黄,万物朦胧,故称黄昏。(北京时间19时至21时)。
- 【亥时】人定,又名定昏等:此时夜色已深,人们也已经停止活动,安歇睡眠了。人定也就是人静。(北京时间21时至23时)。$ ^5 n# y6 o V$ z3 S( [+ O6 ~ U
) ^( \6 I$ }" E/ ?0 L
然后我们来分析一下它昨天发布的内容 - 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 【亥时】铛~铛~铛~铛~铛~铛~铛~铛~铛~铛~
# E* n+ Y. a! U+ f) @ b0 e ~ ^) I& F
根据上面,得出它有以下规律: - 每两个小时发布一条微博,
- 发布时间是偶数小时的0分,这个时间并不是地支时间的开始时间,而是正中间的那个时间点
- 内容是相应的地支时间,加上根据时间而变化的“铛~”的次数,
- “铛~”的次数与时有关,12小时以前与小时相同,12小时以后与[小时减12]相同。
& h9 _( h1 L" R) H8 M u2 c& d
西安钟楼里的钟就是这样敲的吗?去过钟楼一次,没登上去,也没注意。 7 `( S5 i4 L, E7 b3 e
完整代码如下: 需要自行修改App相关值: c% E* \! j! n& o' c& |
: q- s+ E# l0 \9 M: V, ?" a5 I+ s- <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;* ^( B+ Q6 K- @. F1 t$ h
- using System.Collections.Generic;8 o* Y2 ~, I# k1 F: w6 F
- using System.Text;
0 K: z) O- g8 ?! X" N - using NetDimension.Weibo;
' z/ T3 ]* ]- v' _- F - using System.Timers;$ ]0 N) y+ k0 Q# n% G
- using System.Globalization;
0 F7 j6 D+ ^) d/ ?' M0 j - ' a& v4 ]- w! v" s; F( m1 X* U
- namespace WeiboTimer4 U% z# J, e' T. G2 l8 B
- {
$ s- L/ ~- {% z - class Program- E2 K3 b0 l, A
- {/ | Q% a& s9 h
- static string AppKey = "********";
4 l3 _1 @5 p) Y) `: o, A - static string AppSecret = "*******";
8 o: _5 p/ q& t - static string CallbackUrl = "****************";
! @) g- n' r% V: Y6 u - static Timer t = new Timer();
- L W% ]) A( e( r7 Y - static OAuth oauth = null;
l9 n& [* g: m8 [3 L: e4 | ] - static Client Sina = null;4 p' B; E6 a* U$ i
- . C$ i0 h* K7 q, p. ~
- static void Main(string[] args)
/ S$ o: N( |2 ~3 |6 n$ Q - { * n1 j- u K y
- oauth = Authorize();
4 `3 y+ `8 O' ~ - if (!string.IsNullOrEmpty(oauth.AccessToken)){Console.Write("登录成功!");}0 j8 K Z5 N, i7 G! C3 ]# Q
9 a$ p4 F p: s7 O7 A- Sina = new Client(oauth);
$ A3 G; I! Q# u% m/ K+ F# B6 ^3 T( ` - string uid = Sina.API.Entity.Account.GetUID();) I1 y* i1 K- A6 w
- var entity_userInfo = Sina.API.Entity.Users.Show(uid);$ d% r, D% a" H
- Console.WriteLine("昵称:{0},微博地址:http://weibo.com/{1}", entity_userInfo.ScreenName, entity_userInfo.ProfileUrl);
. K/ _2 B7 u' _ h Y0 N# [% l - - W5 n U0 R* t. h( }, R; t
- try
7 v6 f# U* P1 ~% P( q) q! T, C - {; X' r! J& C2 s7 H: o, |2 X8 r
- t.Interval = 1000 * 60; //设置间隔时间为1分钟, H, C+ a2 v6 @. ~4 z
- t.Elapsed += new ElapsedEventHandler(TimerElapsedEvent); //到达时间的时候执行事件;
4 u: O( K, A( }! _5 a6 o - t.AutoReset = true; //设置是执行一次(false)还是一直执行(true); # b7 K8 f0 Q- }7 T0 L) }
- t.Start(); //启动Timer对象;
5 ~4 ]. O% \; X4 i. l: c - }% W) `; d% ]& R
- catch (Exception ex)
% q$ T" H/ L( R0 ]7 z% |6 P - {+ h' T9 I0 Y3 k8 d' w( Q4 P$ d7 O
- Console.WriteLine("定时任务异常:" + ex.Message);- t$ k3 |# W; [& a3 a( `
- t.Stop();
/ B2 _$ J( c8 [! h) e" n - }7 B- a+ ]7 J/ k, R: c! ^. k
- Console.WriteLine("定时任务开始工作。。。");
0 u l( d0 m% K( r# [' Q9 H - Console.ReadKey();
1 S3 K/ j U$ @0 i - }+ U. H. d! h" i; v8 l( }6 k
0 V8 w/ O0 j0 Y% G4 S/ L- static OAuth Authorize(). T0 Y& C1 I* [' Y; K
- {
3 X# ?3 {2 ~: ~3 n4 I; K; w6 e - OAuth o = new OAuth(AppKey, AppSecret, CallbackUrl);
# p' B; d8 F0 \. t7 {) |0 l - while (!ClientLogin(o))9 N1 L) B5 @5 N9 H; ]" a; S" N
- {
, s. c4 w5 a/ x$ Y; _9 B - Console.WriteLine("登录失败,请重试。");
. X( a; V9 X* p9 ~" _9 |$ O - }
7 u9 d! r: i. U6 B - return o;0 ~ \3 j1 r# P5 V( |, D
- }) Z+ F- w2 [& ^% _( ^8 Z' }
- : R# u/ @+ S( A8 I. V8 s6 h* `( l& O1 u
- private static bool ClientLogin(OAuth o)( \4 O# G% ?* X& `
- {
% S7 F8 D# H6 _ - Console.Write("微博账号:");' p( ^' F$ U2 M- w6 K
- string account = Console.ReadLine();# a2 l R' j- }+ f6 [) A
- Console.Write("登录密码:");* A& O7 |' C% C6 L7 R& v/ D# f
- ConsoleColor originColor = Console.ForegroundColor;7 r; Z8 @" [& Z/ I# ?1 p& G `
- Console.ForegroundColor = Console.BackgroundColor; //知道这里是在干啥不?其实是为了不让你们看到我的密码^_^& o, ]% O: m+ n! `3 t* | d
- string password = Console.ReadLine();4 K6 q. K4 l& p6 F. t5 v1 g/ L
- Console.ForegroundColor = originColor; //恢复前景颜色。
# x G4 e: h" `0 e7 E( F - return o.ClientLogin(account, password);% r; t; ^: N0 A
- }6 Q$ q1 ?: a0 o. _
- K# e+ y8 G8 M" }7 C/ A7 G& u1 G( g: {- static void TimerElapsedEvent(object sender, ElapsedEventArgs e)# m2 `4 a g w
- {1 N8 y7 m2 g! y2 k- Z
- DateTime iNow = DateTime.Now;
5 S [, C9 S$ o5 ^$ H5 ^2 V3 v, i - try
; i0 a! D5 m, I* z8 V p - {0 Z* F" p3 G6 o
- string content = makeContent(iNow.Hour, iNow.Minute);- b1 s: K- m& ~& Z2 b
- if (!string.IsNullOrEmpty(content))% |% X6 }; q5 b, \3 D5 b! ~
- {8 U6 q' i1 j7 e; \" Y. F
- var statusInfo = Sina.API.Entity.Statuses.Update(content);
6 w0 E4 o# l1 i" ]5 {; N - DateTime dtCreate = DateTime.ParseExact(statusInfo.CreatedAt, "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture);7 ~5 r, O- A1 p
- Console.WriteLine("本机时间:{0}, 微博时间:{1}, 发布内容:{2}", string.Format("{0:G}", iNow), string.Format("{0:G}", dtCreate), statusInfo.Text);" `7 T1 l& h. s" {* E; n3 y
- }
7 J3 X1 y }) c) T g6 v. {4 Z - }
( c7 j- \4 G3 { C; ]) }$ f2 W) V - catch (Exception ex)
! w4 ~& x I# M - {
' K. d/ f4 W0 P6 A& P: X - Console.WriteLine("定时任务异常:" + ex.Message);
0 u# j7 \) ^1 a8 u8 x+ } - }4 y7 E# R. a! t+ n
- }
! O8 y5 I- g, C; s
; R! N& p% ^) G6 m5 V, f2 P1 I7 n- static string makeContent(int hour24, int minute)
: m+ n! E' j1 W - {7 l8 a* Y( y: s8 _$ @/ X- `* S! b
- string[] diZhi = "子|丑|寅|卯|辰|巳|午|未|申|酉|戌|亥".Split('|');$ f! |- s* b5 `9 o `
- string extWeibo = "";- ~3 I( @& u6 i( G- A
- if (hour24 % 2 == 0 && minute == 0)7 Q& H) ]+ |$ v9 H' A$ A
- {
: }! B' T; B0 {7 {6 e - for (int i = 0; i < ((hour24 >= 12)? (hour24 - 12): hour24); i++)2 a: u7 \* p7 F2 y" P: C
- {
" c4 k0 y" ^8 \, C' f c - extWeibo += "铛~";
L* {/ o) [+ P' ~3 R - }# X" H( l3 I. I% | Y) a N
- return "【" + diZhi[hour24 / 2] + "时】" + extWeibo;/ L$ S: ]( O E% d R8 @
- }3 Q; m9 p& F9 C" ^
- else
2 I; L' }2 j3 N$ u* G. h8 W3 l8 c - {6 a* @+ k1 W. u8 L W! G6 C
- return "";6 u" s4 `. L1 n/ d7 @
- }
; z: {$ J6 Z; \0 ?3 A6 T - }
6 |. h; \" i" F - }( `& E& p) O4 O/ | p$ d
- }
复制代码完整程序下载:
. ~; f$ Z2 x1 P6 l& A* z. Z! r2 y d |
上一篇:微信支付下一篇:微信公众平台开发(66)人品计算
|