大家最近都在热议古城钟楼的红火。不是加V号、不是官方号、不是皇冠会员。没有拟人化,没有段子、没有运营。1天之内从1万不到的粉丝新增了20多万并且还在持续传播和增长粉丝。我不研究它是怎么红起来的,但写个类似的程序实现它却很容易,程序才100行左右:
( H0 a% S2 C/ L# x先来普及一下地支时间与北京时间的对应关系: - 【子时】夜半,又名子夜、中夜:十二时辰的第一个时辰。(北京时间23时至次日01时)。
- 【丑时】鸡鸣,又名荒鸡:十二时辰的第二个时辰。(北京时间01时至03时)。
- 【寅时】平旦,又称黎明、早晨、日旦等:时是夜与日的交替之际。(北京时间03时至05时)。
- 【卯时】日出,又名日始、破晓、旭日等:指太阳刚刚露脸,冉冉初升的那段时间。(北京时间05时至07时)。
- 【辰时】食时,又名早食等:古人“朝食”之时也就是吃早饭时间,(北京时间07时至09时)。
- 【巳时】隅中,又名日禺等:临近中午的时候称为隅中。(北京时间09时至11时)。
- 【午时】日中,又名日正、中午等:(北京时间11时至13时)。
- 【未时】日昳,又名日跌、日央等:太阳偏西为日跌。(北京时间13时至15时)。
- 【申时】哺时,又名日铺、夕食等:(北京时间15时至17时)。
- 【酉时】日入,又名日落、日沉、傍晚:意为太阳落山的时候。(北京时间17时至19时)。
- 【戌时】黄昏,又名日夕、日暮、日晚等:此时太阳已经落山,天将黑未黑。天地昏黄,万物朦胧,故称黄昏。(北京时间19时至21时)。
- 【亥时】人定,又名定昏等:此时夜色已深,人们也已经停止活动,安歇睡眠了。人定也就是人静。(北京时间21时至23时)。: H* y+ ]7 w" l5 L* |$ D
& t, P8 u; V9 E+ B1 m
然后我们来分析一下它昨天发布的内容 - 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 g$ I; {. w: r$ i3 z
0 Y* A: A3 O8 ?; U0 t
根据上面,得出它有以下规律: - 每两个小时发布一条微博,
- 发布时间是偶数小时的0分,这个时间并不是地支时间的开始时间,而是正中间的那个时间点
- 内容是相应的地支时间,加上根据时间而变化的“铛~”的次数,
- “铛~”的次数与时有关,12小时以前与小时相同,12小时以后与[小时减12]相同。
9 ?1 D* K2 l$ g/ c0 j
西安钟楼里的钟就是这样敲的吗?去过钟楼一次,没登上去,也没注意。 ; A5 A/ V/ t" o8 O9 q( o0 Y
完整代码如下: 需要自行修改App相关值:
: ?& P4 T# u0 b( q: g s2 v3 B
/ E X2 d ^- s% c- <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;
. [" ~* g. C& L7 w; A& b - using System.Collections.Generic;; f) c& V* `* M5 w
- using System.Text;
- G% x# b( |$ y! o: [( T( i - using NetDimension.Weibo;
i# P Y6 k/ f( n4 x h+ i9 M& \ - using System.Timers;
+ P2 N/ }. P6 o8 s3 }3 A3 y - using System.Globalization;' _7 b+ G, O, O I& C p. [
- 7 d/ |" V5 s' l) D, t( ~# ?; _
- namespace WeiboTimer9 w0 x- X% j! n5 g( K
- {
# B% c. ]) D( q0 r7 O! @1 y0 |; g, @ - class Program
) j5 z6 P2 }" W3 O - {
5 u0 C+ G; k. q: J# N! m4 b* _ - static string AppKey = "********";
4 t; A0 G0 l! V% f( y2 T; V - static string AppSecret = "*******";
6 ]8 P7 A5 g& b0 {+ J5 S - static string CallbackUrl = "****************";
: Z, T8 G5 }6 L. w& S. } - static Timer t = new Timer();, |; ^2 t/ d' C
- static OAuth oauth = null;
0 t' K# b; `* q - static Client Sina = null;
0 a! T4 G: J% v( w, d
4 A# c1 H+ e+ m j$ M5 g3 p- static void Main(string[] args)
* @% i& K, ~1 s) S: w% ? - {
- e; _8 a3 R" j/ c3 N* p - oauth = Authorize();9 |) k8 M! b3 s/ Q5 {/ `& J
- if (!string.IsNullOrEmpty(oauth.AccessToken)){Console.Write("登录成功!");}
/ s1 J: a" d" ^7 w; A/ P
* H. v2 k& S4 n6 p O7 h$ E- Sina = new Client(oauth);0 C4 ~, Q# r/ p1 t5 l
- string uid = Sina.API.Entity.Account.GetUID();
" Q/ J) L0 }9 c& |6 [ - var entity_userInfo = Sina.API.Entity.Users.Show(uid);
; Z* N3 \& j9 W' G- W - Console.WriteLine("昵称:{0},微博地址:http://weibo.com/{1}", entity_userInfo.ScreenName, entity_userInfo.ProfileUrl);- L# T/ V9 e2 L3 I$ w
- ( c4 b3 C3 Y) ?1 }1 b% d3 O
- try
' \. [ @- `9 q4 V& z% x# ] - {+ z& S }4 n, y
- t.Interval = 1000 * 60; //设置间隔时间为1分钟1 z" I+ U) f+ l y- T4 T/ y! c
- t.Elapsed += new ElapsedEventHandler(TimerElapsedEvent); //到达时间的时候执行事件; - _" S5 D5 u% ~9 {* i }
- t.AutoReset = true; //设置是执行一次(false)还是一直执行(true);
3 [: w2 a& e! [( Q - t.Start(); //启动Timer对象; / \! E- e( _4 S* d
- }
5 Y, j$ _( {! l& `7 Z - catch (Exception ex)$ P. }/ e" Z( ] c
- {% z$ }, J! F1 q# ~ p9 y
- Console.WriteLine("定时任务异常:" + ex.Message);
! I& o4 w# Z2 V: @) ?! q - t.Stop();
d! H, R, q+ h2 |0 a - }
, d- ^1 Q. J' u! l0 m& v - Console.WriteLine("定时任务开始工作。。。");- S! M/ M* ^# M% ^
- Console.ReadKey();
& D- S+ S$ z/ K' q - }- F7 }% C5 A+ e* T! s2 N+ v4 w
/ [1 @2 l. l/ l6 A- static OAuth Authorize()9 T' _* [: I: h6 l7 E d. n
- {/ B9 d; |) G* l/ Y' L4 H+ M$ v
- OAuth o = new OAuth(AppKey, AppSecret, CallbackUrl);: X* H% [ M; ]1 V, b7 A7 I
- while (!ClientLogin(o))# Y! c: ]+ o2 e6 A, d G
- {, ~, U) b, A3 H/ K# h5 s. h
- Console.WriteLine("登录失败,请重试。");5 B, M: [' m$ S0 ^$ I! t) C
- }& [; k% l6 i6 I/ b- |7 \$ K# H
- return o;2 X, G2 e0 T! c9 @7 z
- }
8 d5 F1 D2 _, ~4 J
$ E6 g- w, ^5 d6 B# r/ ^% J- private static bool ClientLogin(OAuth o)! `0 V3 x& `) I
- {- D! ~* R& t) L8 o& c9 h/ [" R
- Console.Write("微博账号:");6 Q, v+ D, M5 q% D
- string account = Console.ReadLine();( B1 y0 ] }( [7 F6 d
- Console.Write("登录密码:");
" v+ r( G" e3 [ - ConsoleColor originColor = Console.ForegroundColor;5 e9 X% i$ t: _: I q. E; Q: }0 w' F
- Console.ForegroundColor = Console.BackgroundColor; //知道这里是在干啥不?其实是为了不让你们看到我的密码^_^$ Q) P* `$ u) N* D$ `
- string password = Console.ReadLine();
' ?8 l1 N8 _3 h. D& R# r, } - Console.ForegroundColor = originColor; //恢复前景颜色。* z8 _! E+ x6 G* j& V
- return o.ClientLogin(account, password);
! p* D( ]8 z8 n: X - }
, q! \# o; S7 G+ g! p* x% Y - ' M4 v4 ?- w: W; B! u6 N+ [
- static void TimerElapsedEvent(object sender, ElapsedEventArgs e)
$ p2 O6 j/ Q1 c+ ?" ?5 S - {
+ _4 {* d5 A) q1 t( E# N3 R - DateTime iNow = DateTime.Now;8 C" z7 U0 n1 `* z9 l! c
- try
" W( B: N% T: j1 [ - {, F" K1 j4 }' T6 v' @
- string content = makeContent(iNow.Hour, iNow.Minute);+ i& g! `" h- N% S: l& P
- if (!string.IsNullOrEmpty(content))& q6 Y; t( j2 T) q) B; |& @" d0 I
- {( _/ D* i1 f4 G% y; Y% U7 V v: d
- var statusInfo = Sina.API.Entity.Statuses.Update(content);* m& |' F/ W9 \* k o
- DateTime dtCreate = DateTime.ParseExact(statusInfo.CreatedAt, "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture);
) z; W" K. e' a: Q1 T. Z - Console.WriteLine("本机时间:{0}, 微博时间:{1}, 发布内容:{2}", string.Format("{0:G}", iNow), string.Format("{0:G}", dtCreate), statusInfo.Text);% B7 `& i# S/ X2 O) Y* A
- }
/ [. G9 o4 P2 [ - }
' C6 e% d# P& U7 N3 V. } ` - catch (Exception ex)" M9 D' r9 h- r' W R
- {
9 [* ^/ m2 z# h - Console.WriteLine("定时任务异常:" + ex.Message);9 y: v7 y, V: [; _ H, S
- }1 x/ V( M. @8 L6 `, d
- }+ x8 D$ E9 H2 ]; Q. R% D
: Z. t- |2 J. S- static string makeContent(int hour24, int minute)7 p8 R7 C- v# K
- {
: C4 H9 ?- N( F2 g5 J. W - string[] diZhi = "子|丑|寅|卯|辰|巳|午|未|申|酉|戌|亥".Split('|');0 J$ f8 f: i1 }1 e7 i/ m2 T5 l
- string extWeibo = "";
) K8 O e4 {: i- i) } - if (hour24 % 2 == 0 && minute == 0)
$ B4 P* ]9 |% G - {
: `* \, s7 n" [/ l, T2 L - for (int i = 0; i < ((hour24 >= 12)? (hour24 - 12): hour24); i++): P& x, z( p- I8 p
- {
6 `7 S. x, E t7 }) ^) ?! n - extWeibo += "铛~";
+ V, v9 P4 H; |1 s1 k2 L8 m - }
: D- N; L& j; O4 e - return "【" + diZhi[hour24 / 2] + "时】" + extWeibo;
% N) b; y5 ~' b/ j: a" \ - }
* |4 b" E$ U- b+ `* d8 f9 i - else S+ j) H1 G2 ]; w4 n
- {2 v, N; F) I* \3 t& T
- return "";
; p& }% D: p% }4 R - }
. O: f2 M B- I - }& W( Z# B( F4 d8 Q: W+ @/ ~! A
- }
( s. r" F9 U; f0 O5 f - }
复制代码完整程序下载: / w& F# i, d; X; u
|
上一篇:微信支付下一篇:微信公众平台开发(66)人品计算
|