java 板


LINE

(更新说明方式)请问大家如何将code不要写死,不需要重新编译code就有扩充性 对不起,之前描述太简略,让大家都听不懂。 如果听不懂我说的问题,麻烦请大家跟我说。 1.1 写入google calendar 网页 写一个HTML网页,让使用者可以选"两个title选项"选择一POST到servlet, 透过servlet(使用gdate)把选好title data 写入 Google 日历 PS:google calendar 目的是 记录使用者资料 ----------------------------------------------------------------------------- 1.2 抓取google calendar 程式 已知写入google日历有两个事件选项。 自己用gdata for java 抓取 google calendar 每一天所有 title , 之後并区分(分类)title再写入DB. PS:一天中会做"看书"、"吃饭" 、"看书"...等 很多title, 从 google calendar 全部抓出title 并计算每个title花费时间...等。 再区分(分类)title写入自己DB" 以上Code已经写好了 PS:抓出google calendar资料目的是要写入自己DB,日後要做资料上研究分析 -------------------------------------------------------------------------------------------------------------------------------- 现在要把程式变成活(不能重新编译)的改成 2.1 写入google calendar 网页 如果要将原本html网页两个选项"扩充,新增" 第多个 title选项 (三个四个以上) 2.2 抓取google calendar 程式 再抓取google calendar时,必须先得知(html网页)有多少title并将title区分分类并写 入自己的DB PS:如果 写入google calendar 网页 有3个title ,那 抓取google calendar 程式 必 须要区分分类 3个title 写入自己DB PS:如果 写入google calendar 网页 有4个title ,那 抓取google calendar 程式 必 须要区分分类 4个title 写入自己DB -------------------------------------------------------------------------------------------------------------------------------- 目前我知道重新改写解决这问题,如果 不能改写code重新编译,要如何 设计 撰写 呢? ========================================================================================== public class test { private static String id = "[email protected]"; private static String pw = "pw"; private static String StartYear = "2009"; private static String StartMonths = "08"; private static String StartDay = "01"; private static String EndYear = "2009"; private static String EndMonths = "10"; private static String EndDay = "01"; private static float titelnum011 = 0; private static float titelnum012 = 0; private static String titel011 = "日历"; private static String titel012 = "meeting"; private static int num01 = 0; private static int daynum011 = 0; private static int daynum012 = 0; public static void main(String args[]) throws ServiceException, IOException, ParseException { SimpleDateFormat formatter = new SimpleDateFormat("yyyy" + "-" + "MM" + "-" + "dd"); Date date1 = formatter.parse(StartYear + "-" + StartMonths + "-" + StartDay); Calendar calendar = Calendar.getInstance(); calendar.setTime(date1); Date date2 = formatter.parse(EndYear + "-" + EndMonths + "-" + EndDay); long total = (date2.getTime() - date1.getTime()) / (1000 * 60 * 60 * 24) + 1; System.out.println("总共 " + total + " 天数"); //============================================================================= CalendarService myService = new CalendarService("exampleCo-exampleApp-1"); myService.setUserCredentials(id, pw); URL feedUrl = new URL("http://www.google.com/calendar/feeds/default/private/full"); CalendarQuery myQuery = new CalendarQuery(feedUrl); int day = 0; //============================================================================= while (calendar.getTime().compareTo(date2) <= 0) {//一天一天抓取,解决 google一次只能抓取25DATA int y = calendar.get(Calendar.YEAR); int m = calendar.get(Calendar.MONTH) + 1; int d = calendar.get(Calendar.DATE); day = day + 1; String yyy = String.valueOf(y); String mmm; if (m < 10) { mmm = String.valueOf(m); mmm = "0" + mmm;//符合google api 输入日期格式 } else { mmm = String.valueOf(m); } String ddd; if (d < 10) { ddd = String.valueOf(d); ddd = "0" + ddd;//符合google api 输入日期格式 } else { ddd = String.valueOf(d); } //============================================================================= myQuery.setMinimumStartTime(DateTime.parseDateTime(yyy + "-" + mmm + "-" + ddd + "T00:00:00")); myQuery.setMaximumStartTime(DateTime.parseDateTime(yyy + "-" + mmm + "-" + ddd + "T23:59:59")); // Send the request and receive the response: CalendarEventFeed resultFeed = myService.query(myQuery, CalendarEventFeed.class); int size = resultFeed.getTotalResults();//取得日历当天是否有资料笔 数 if (size != 0) { for (int i = 0; i < resultFeed.getEntries().size(); i++) { CalendarEventEntry entry = resultFeed.getEntries().get(i); String title = entry.getTitle().getPlainText();//日历事件 //============================================================================= When t = entry.getTimes().get(0); DateTime start = t.getStartTime(); String s = start.toUiString(); int aa = (int) start.getValue();//日历title开始时间 DateTime end = t.getEndTime(); String e = end.toUiString(); int bb = (int) end.getValue();//日历title结束时间 int cc = (bb - aa) / 1000 / 60;//计算日历title花费时间 float dd = (float) (cc / 60f); //========================================================== // 当 输入(post)google日历事件选项 新增第三笔" // 再 抓取google资料时必须要改写并"新增第三笔"并区分事件 (titel)分别写入DB // 如何把下程式码写活的, 具备扩充性, if (title.equals(titel011) || title.equals(titel012)) { System.out.println(); System.out.println("开始 " + s); System.out.println("事件 " + (i + 1) + " " + title); System.out.println("结束 " + e); System.out.println("花费时间 " + dd + "小时"); System.out.println("~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~"); if (title.equals(titel011)) { daynum011 = daynum011 + 1; titelnum011 = titelnum011 + dd; } if (title.equals(titel012)) { daynum012 = daynum012 + 1; titelnum012 = titelnum012 + dd; } //========================================================== }//for }//if } calendar.add(Calendar.DAY_OF_YEAR, 1);//while//日期加一天 }//while //统计各项事件 总次数 总时数 System.out.println("事件一 " + titel011 + " 总次数 " + daynum011 + " 总时数 " + titelnum011); System.out.println("事件二 " + titel012 + " 总次数 " + daynum012 + " 总时数 " + titelnum012); } } --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 210.240.197.117
1F:→ xlk:完全不OO 如果不能改写重新编译就砍掉重练XD 10/19 20:14
2F:推 slalala:从CODE看 的确不OO 10/19 20:33
3F:→ xlk:程式中判断是否符合title的部分 若不改写独立到class外怎麽活? 10/19 20:44
4F:推 slalala:感觉没有那麽惨 如果OO化 应该可透过小技巧加上IoC 10/20 01:15
5F:→ xlk:写活是什麽意思? 跟不能重新编译不是矛盾吗? 原po请解释一下ꀠ 10/20 02:07
6F:推 costbook:我猜是如何设计UI的问题 10/20 05:57
7F:→ nation6238:写活的意似是 随时能增加 title.equals("事件一") 10/20 13:26
8F:→ nation6238:随时增加或减少title.equals判断 10/20 13:28
9F:→ nation6238:网页UI部分因该可以用AJAX办到吧 10/20 13:31







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Soft_Job站内搜寻

TOP