大家最近都在热议古城钟楼的红火。不是加V号、不是官方号、不是皇冠会员。没有拟人化,没有段子、没有运营。1天之内从1万不到的粉丝新增了20多万并且还在持续传播和增长粉丝。我不研究它是怎么红起来的,但写个类似的程序实现它却很容易,程序才100行左右:
+ _. z- e- }" d2 r s! 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时)。5 t& E6 p5 k/ Z
) M9 W+ e% Y( C9 a6 }" 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 【亥时】铛~铛~铛~铛~铛~铛~铛~铛~铛~铛~
' o9 p! S* c' R5 I% V2 v# [ 9 o! r( d; |) z3 F/ H
根据上面,得出它有以下规律: - 每两个小时发布一条微博,
- 发布时间是偶数小时的0分,这个时间并不是地支时间的开始时间,而是正中间的那个时间点
- 内容是相应的地支时间,加上根据时间而变化的“铛~”的次数,
- “铛~”的次数与时有关,12小时以前与小时相同,12小时以后与[小时减12]相同。
& {& y8 j% r8 z0 e; J
西安钟楼里的钟就是这样敲的吗?去过钟楼一次,没登上去,也没注意。 . a9 V; X8 E) `
完整代码如下: 需要自行修改App相关值: ! T- F( R+ `1 Q1 _
7 m* F% o) I) r8 V. a7 s& k- <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;! o& i. k8 E9 [9 l$ S; m
- using System.Collections.Generic;
9 a# }. ~! w- t6 N) o - using System.Text; l* [5 H2 A Z
- using NetDimension.Weibo;) o+ T7 l* f$ Z6 W
- using System.Timers;; }) v: G8 e3 ]' ` D- F. s$ H$ i
- using System.Globalization;1 ]5 v% _- N- b( m! Z
/ @1 [8 C5 S0 [6 C, }' g- namespace WeiboTimer. {# }: t5 b/ h) k+ z. r7 j
- {8 j( U4 Q& @( {8 G
- class Program
2 U0 m: K3 g( I7 v1 |2 | - {
2 R% [2 Y3 }* { m: R" W - static string AppKey = "********";
0 y- h: z2 f- z0 c" R - static string AppSecret = "*******";- T# E6 ?' n% b/ h$ |' S; J
- static string CallbackUrl = "****************";
+ t" E+ O7 Z# F. l2 Z8 W6 \8 t0 b _ - static Timer t = new Timer();' H' u% l' l% ~- w3 r
- static OAuth oauth = null;4 G, U7 |& O$ o" [4 G
- static Client Sina = null;% \6 o% y0 }9 ^7 f z
- . X3 Y& Y/ }+ @" Z0 \
- static void Main(string[] args)5 {. _" }+ c4 R2 ]4 o- z1 r
- {
+ E# w3 M/ d6 X4 ?4 C - oauth = Authorize();3 l. j. E$ u2 R* B( a' h7 Z. j _
- if (!string.IsNullOrEmpty(oauth.AccessToken)){Console.Write("登录成功!");}
$ O9 X7 c' d" p - 5 \5 m- u n+ J, L
- Sina = new Client(oauth);
/ b+ W. m8 Y, U - string uid = Sina.API.Entity.Account.GetUID();/ w% ], k! ~6 Q) ]1 S$ w$ f+ a
- var entity_userInfo = Sina.API.Entity.Users.Show(uid);" D0 n. A/ |8 [, m) t
- Console.WriteLine("昵称:{0},微博地址:http://weibo.com/{1}", entity_userInfo.ScreenName, entity_userInfo.ProfileUrl);' `5 h/ r# h& }' O C
" E! [. U( j4 ^- try* b3 g7 G; o% v8 ]" {9 u
- {8 m( j( o" T6 |) i/ ^: S& m' [
- t.Interval = 1000 * 60; //设置间隔时间为1分钟1 i4 }# n; z. ~) X+ X4 m
- t.Elapsed += new ElapsedEventHandler(TimerElapsedEvent); //到达时间的时候执行事件;
5 q8 U. M$ w, W8 H- p4 G, F - t.AutoReset = true; //设置是执行一次(false)还是一直执行(true);
1 r0 t; ~8 n5 l2 Z. L* c! X5 O; `+ p - t.Start(); //启动Timer对象;
7 X" a5 ?) U. J1 P; U - }
+ }* ]9 Z+ s- ^2 z+ j - catch (Exception ex)
, Z5 D0 Q. l9 d" f M - {5 a! N9 u" p. F) y. f
- Console.WriteLine("定时任务异常:" + ex.Message);
/ o4 L1 h6 O/ c8 L; P1 | - t.Stop();
2 W9 r5 Y6 h6 W: G [ - }
0 h3 V/ m; f$ [6 a3 e - Console.WriteLine("定时任务开始工作。。。");
5 c4 F, ?# y. s9 `; d: y G - Console.ReadKey();# {6 D4 q3 T! Y p
- }* w: l. R/ p- M4 K1 K, K
- , ?( b* m! _4 C
- static OAuth Authorize()6 B5 O3 `# B6 _$ L& q
- {" I: m# P/ h) E. ^' |0 b! W
- OAuth o = new OAuth(AppKey, AppSecret, CallbackUrl);% b8 f2 ? @5 W; z2 h
- while (!ClientLogin(o))
- Z+ p! f1 a2 a" ? - {- v8 {5 x. w4 f& }$ Z9 I9 Q
- Console.WriteLine("登录失败,请重试。"); ~) b8 m* r9 a
- }1 c& M8 |: c/ m. x% _9 n f* q, u
- return o;
: h3 X2 ^- h$ K8 O; i) S - }
! V9 u4 d, T' H: B! H% \# `
$ v! Y3 D7 i9 g2 m5 A- private static bool ClientLogin(OAuth o)
- D) V* ^% Y* _. [ - {2 k# _/ |0 o7 o
- Console.Write("微博账号:");9 [0 r- e4 ]" u5 _* n- n
- string account = Console.ReadLine(); u9 g# Z) s, F8 G8 ?3 J
- Console.Write("登录密码:");
5 U5 T0 s e! x - ConsoleColor originColor = Console.ForegroundColor;
3 u5 f! ]0 |6 U4 r, i - Console.ForegroundColor = Console.BackgroundColor; //知道这里是在干啥不?其实是为了不让你们看到我的密码^_^
0 Z/ Z6 I8 C( S - string password = Console.ReadLine();
. B ^( Y; h* Q. d& N; [ - Console.ForegroundColor = originColor; //恢复前景颜色。- Z& @) A; E4 n. N5 r+ w; B
- return o.ClientLogin(account, password);) P8 H* L9 D. o- S5 p
- }$ V& t4 b- ~' l" m
- , n7 z0 [ J7 s) N1 U% |% W1 r
- static void TimerElapsedEvent(object sender, ElapsedEventArgs e)" g3 P. V4 N0 C+ j! x
- {
2 T* m% ^9 d0 m: r9 o - DateTime iNow = DateTime.Now;
5 Y3 O$ [$ D6 z. A0 B# Y* M - try
, _+ l e+ n- @7 X+ e5 k* e - {
) O1 d% n5 |3 z, m' k9 J1 K* L+ P - string content = makeContent(iNow.Hour, iNow.Minute);
4 k v8 z4 ^; ~8 L* N# j - if (!string.IsNullOrEmpty(content))
, u* \. s: \# y" V& q - {/ w8 `( M$ S0 Z+ a/ g9 ?3 u' {
- var statusInfo = Sina.API.Entity.Statuses.Update(content);0 G& q, J) X, `! U5 i( _; K0 m$ `
- DateTime dtCreate = DateTime.ParseExact(statusInfo.CreatedAt, "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture);
$ d+ m2 i$ U; e; s q - Console.WriteLine("本机时间:{0}, 微博时间:{1}, 发布内容:{2}", string.Format("{0:G}", iNow), string.Format("{0:G}", dtCreate), statusInfo.Text);/ d! ?2 q* { y, A) ?: d$ {
- }
5 J/ r) ~. U$ d+ M; g, \) D - }" L0 B# Q# B1 g8 n. u3 t9 \; ^% J
- catch (Exception ex)
! w* f) i2 S$ }. I - {
' Z$ R0 A$ W! k/ D3 v. C/ D$ o - Console.WriteLine("定时任务异常:" + ex.Message);/ z% \/ D9 h: l) O" l
- }
# b/ w! _# _- K7 I1 z) X - }
3 V6 ^8 y8 u% h - / |; s7 E5 C ~3 c
- static string makeContent(int hour24, int minute)% V' z# _/ O Y `
- {" T( q9 g/ w) M* F$ R
- string[] diZhi = "子|丑|寅|卯|辰|巳|午|未|申|酉|戌|亥".Split('|');
( \# I1 E1 n! ? ? [% }" l - string extWeibo = "";
+ |2 k% D( N( J, ?( P' e - if (hour24 % 2 == 0 && minute == 0)* k9 u( u" w' h/ m6 u3 A+ o
- {' F2 R# W9 t4 P* }% k
- for (int i = 0; i < ((hour24 >= 12)? (hour24 - 12): hour24); i++)+ v5 r6 K( H; {
- {
]1 O& I& y: H+ G - extWeibo += "铛~";
; D. ?( W. ], v7 F - }4 n! Y3 q2 B* g4 ^$ B
- return "【" + diZhi[hour24 / 2] + "时】" + extWeibo;+ o. n4 x2 s% F0 d4 [
- }
8 Q- q3 k; s3 n2 e5 `: K - else8 V, M, G, R# w' Y# M: {) V7 y
- {7 }; |- C7 d7 z
- return "";
# J) B3 O5 {/ r! ` - }
+ B' D3 r% [) k - }$ [ m+ G7 D) P3 q) X4 V0 G y
- }9 _9 B/ ]* v0 j# _/ _# I
- }
复制代码完整程序下载:
& B( ~' g* W: g: @5 Z G) k# D3 Y |
上一篇:微信支付下一篇:微信公众平台开发(66)人品计算
|