|
大家最近都在热议古城钟楼的红火。不是加V号、不是官方号、不是皇冠会员。没有拟人化,没有段子、没有运营。1天之内从1万不到的粉丝新增了20多万并且还在持续传播和增长粉丝。我不研究它是怎么红起来的,但写个类似的程序实现它却很容易,程序才100行左右:
: y5 M" Z( W) B/ g% 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时)。- ^- |% n( [* Z+ Y
2 F- f( b# ]2 V4 e7 m% j5 f/ |7 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 【亥时】铛~铛~铛~铛~铛~铛~铛~铛~铛~铛~
4 O3 S8 H. \3 n # G" y) v; H; P5 T
根据上面,得出它有以下规律: - 每两个小时发布一条微博,
- 发布时间是偶数小时的0分,这个时间并不是地支时间的开始时间,而是正中间的那个时间点
- 内容是相应的地支时间,加上根据时间而变化的“铛~”的次数,
- “铛~”的次数与时有关,12小时以前与小时相同,12小时以后与[小时减12]相同。
$ ^+ b- R8 D4 ~( S7 a: S2 h( T
西安钟楼里的钟就是这样敲的吗?去过钟楼一次,没登上去,也没注意。 N" t' n0 o* T X9 o: t
完整代码如下: 需要自行修改App相关值:
! `* S* p, F L' ^* U- y& k7 s- . m1 W- V2 ]3 ]* J
- <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;' l7 z4 [+ A/ I. y" Q" @9 r2 n: T
- using System.Collections.Generic;
) V8 p0 p8 X0 }8 G8 _ - using System.Text;
& H0 M, L, \9 S) S- g - using NetDimension.Weibo;' [6 \9 \6 i0 M. S/ a6 |# I; B4 L6 Y
- using System.Timers;
3 z; D+ [) p3 H+ f' Q0 n; ] - using System.Globalization;
# f* R: K2 g! T/ M0 Q* E
3 E) T* i4 q7 A0 q/ m- namespace WeiboTimer$ R7 w! Q% U5 l# }" }$ K) C4 `
- {; p1 N9 u: }2 r$ a' T: Y9 j1 ]
- class Program4 ^- C3 z0 Y7 }; o3 V5 P: D
- {- l: g, V- ~1 t" h6 ^3 u
- static string AppKey = "********";
8 q% p( Q, {( k" | - static string AppSecret = "*******";+ k, V7 C# J5 m4 v6 O
- static string CallbackUrl = "****************";
* m- b& s+ C" R# k! b$ ^ - static Timer t = new Timer();5 G% }0 A0 A4 Z6 L5 c
- static OAuth oauth = null;
! ^7 {( W0 v% ]1 h" j9 x: i - static Client Sina = null;
' y- f8 N0 _9 p$ D8 E* y9 x - " m+ {6 K+ W4 Y- ]* O
- static void Main(string[] args)! _* J6 F8 u: q1 D" T% E K
- {
) W: ]& {, g* n - oauth = Authorize();. d% n% z6 A3 ^9 C: A2 B" E
- if (!string.IsNullOrEmpty(oauth.AccessToken)){Console.Write("登录成功!");}' O) Z' G( b( Y: c0 C0 |
- / R& N' D% s, A# z/ _+ Q- R
- Sina = new Client(oauth);) I" \2 T9 `8 F) u" Q4 W
- string uid = Sina.API.Entity.Account.GetUID(); V5 w, h! R3 @4 s- n) D
- var entity_userInfo = Sina.API.Entity.Users.Show(uid);
0 P# s+ g% W: V' y - Console.WriteLine("昵称:{0},微博地址:http://weibo.com/{1}", entity_userInfo.ScreenName, entity_userInfo.ProfileUrl);* U4 @& G& q8 k0 s3 y+ u
- 3 ^* e( E9 c9 ~5 m
- try/ P2 C+ s; Q# o8 r
- {
0 H- v9 s6 |( ?! ` - t.Interval = 1000 * 60; //设置间隔时间为1分钟: ~2 e* C+ I, g" x! R5 X
- t.Elapsed += new ElapsedEventHandler(TimerElapsedEvent); //到达时间的时候执行事件;
# h- s% ]; m1 @ R0 K" g - t.AutoReset = true; //设置是执行一次(false)还是一直执行(true);
5 `) O8 {" |- M0 `1 A" @" {( N - t.Start(); //启动Timer对象;
+ f5 g8 ?" c; W5 f/ g' m - }6 r1 t1 C, I0 K& }/ c# x3 U* y
- catch (Exception ex)8 N' _, A1 [6 B N6 H
- {
; R& R7 a" q$ ?! P - Console.WriteLine("定时任务异常:" + ex.Message);
! { J0 [$ R; v3 j g; F - t.Stop();7 Y( a( X* c5 L: `# W9 ?
- }' _2 B# P+ r% e. G# P
- Console.WriteLine("定时任务开始工作。。。");1 R5 S( z9 v. s6 Z
- Console.ReadKey();
5 \$ i' [1 y) Z/ @% C - }
6 e$ S; _# \; |& H - 6 p# W* ?/ L: N" Y, Q- m# V' `
- static OAuth Authorize()
9 L1 V; u, L% }& B7 h a - {: Y" D6 y6 p0 R: E2 o6 X" v7 ?5 c) C6 Q
- OAuth o = new OAuth(AppKey, AppSecret, CallbackUrl);
- N: Q8 G" y1 g - while (!ClientLogin(o))5 A6 C; o. v3 J. {8 a" \7 Z
- {$ H" u- g4 d9 x# n
- Console.WriteLine("登录失败,请重试。");
/ [; A3 E' c# t# ^# { - }
) B- u6 K9 t" n7 m. r+ q - return o;
1 F* u0 @ ?) T+ ] - }
9 H8 G; f+ }: _' v; ?! f
. t* t1 \- i* L: _- _. C9 _- private static bool ClientLogin(OAuth o)
9 J) Q; T6 c# N" z I - {( N# b; c/ p h$ F! H
- Console.Write("微博账号:");0 d" Z4 a- ^7 W
- string account = Console.ReadLine();+ |# h7 X' P, L6 _! V: q9 P. R
- Console.Write("登录密码:");4 C+ R% T$ |0 l+ m7 E
- ConsoleColor originColor = Console.ForegroundColor;
# P1 T- N0 O. R) k - Console.ForegroundColor = Console.BackgroundColor; //知道这里是在干啥不?其实是为了不让你们看到我的密码^_^
& E2 B$ {4 A1 @, F' ]6 _ - string password = Console.ReadLine();
/ k. ?+ o' E, I3 i( _- S - Console.ForegroundColor = originColor; //恢复前景颜色。; r& A) W" s& `( u
- return o.ClientLogin(account, password);7 ^ L$ n5 h) W4 `# ~: a$ H' h
- }
6 P& {. m; @( Q# S, g c - + {8 t7 Z# B* h' `7 a0 j1 Z; c
- static void TimerElapsedEvent(object sender, ElapsedEventArgs e)
( C8 M* a; v7 ~6 h) } - {
5 z3 N- S# ^" ~; Y! ? - DateTime iNow = DateTime.Now;! Y! G' L$ u, Q. t! e- }; l
- try
" y3 f K! C. d# [) N- N - {/ P$ U, s+ j4 s; }, i8 E
- string content = makeContent(iNow.Hour, iNow.Minute);4 k- p1 |6 i: w, ]1 T6 O; V
- if (!string.IsNullOrEmpty(content))
4 R! [! q9 c- j" u! E: k - {
- P+ y% u5 a8 q% H - var statusInfo = Sina.API.Entity.Statuses.Update(content);
6 S+ M. x2 H- W3 m+ F. Y - DateTime dtCreate = DateTime.ParseExact(statusInfo.CreatedAt, "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture);
/ l" [, x2 `7 A' [+ S3 ^3 g& y. Z6 p - Console.WriteLine("本机时间:{0}, 微博时间:{1}, 发布内容:{2}", string.Format("{0:G}", iNow), string.Format("{0:G}", dtCreate), statusInfo.Text);8 c9 B! c0 L6 y! ?3 Q# |" M% b
- }
/ [% @7 @9 e" }# Z( S0 x9 ^ - }# \* R# g6 M; G" N# n2 v
- catch (Exception ex)! X8 S; u& Q7 z8 w5 v' @5 Q4 I$ i& j: [
- {. ]' [+ w; B9 V6 G& w
- Console.WriteLine("定时任务异常:" + ex.Message);$ n$ B* G4 i' X
- }+ F2 }, @; e, L3 O
- }
/ l1 A- |; a: s' `( ? Y3 `
: t& r/ J8 ^0 c7 f0 h' d: y- static string makeContent(int hour24, int minute)
S- ?, H `0 N7 o2 d7 y8 E& D - {
+ n6 d; S! f* d1 L. l' n) f - string[] diZhi = "子|丑|寅|卯|辰|巳|午|未|申|酉|戌|亥".Split('|');
1 c2 U4 O. P& I2 [4 _; Q - string extWeibo = "";
% d. f. { Q0 T$ U' r9 p3 T2 J& m - if (hour24 % 2 == 0 && minute == 0)
5 V" l: A8 F( {8 }# G$ b6 @( K3 S - {# H" R4 H) ?* E! e+ t5 A1 n Z
- for (int i = 0; i < ((hour24 >= 12)? (hour24 - 12): hour24); i++)) H& U2 T/ P0 B; N5 w4 t8 k8 u
- {
1 A4 t0 H) ]9 m4 B0 r/ n1 j - extWeibo += "铛~";
0 s+ k% O$ j1 ]7 r- z* i - }) n K7 h- t# Y' b
- return "【" + diZhi[hour24 / 2] + "时】" + extWeibo;% \5 C: a2 `% |( W; {2 ^5 l
- }; v/ T* a& z* [+ e# p7 P$ C
- else
1 [0 F, |; d) y, c. h6 z- G' a - {
- p: a7 T/ ?3 ^0 y - return "";: Z2 C& s/ q+ X, m" B
- }
2 k x) L" p! ~3 o - }) p2 r a, e) E- H# U$ k
- }
4 H9 M: `" y, h - }
复制代码完整程序下载:
4 N/ y, X- a$ ?; j4 G |
上一篇:微信支付下一篇:微信公众平台开发(66)人品计算
|