分類
程序 网站

自动检查网页更新

需求:http://www.cnca.gov.cn/ywzl/gjgnhz/jkzl/这个网页会公布进口水产品境外生产企业注册名单,但公布日期不一定,所以想自动检查美国(2014年07月21日)这个条目是否更新了,如果更新了发邮件通知我。方法:获取网页,查看网页是否存在“美国(2014年07月21日)”若不存在则更新了。发邮件用PHPMailer的SMTP发送邮件很方便。

check.php

<?php
ignore_user_abort();//关掉浏览器,PHP脚本也可以继续执行.
set_time_limit(0);//通过set_time_limit(0)可以让程序无限制的执行下去
$interval=60*60*10;//单位是秒,每10小时执行一次
do{
	$run = include 'config.php';
	if(!$run) die('process abort');
	
	$url = "http://www.cnca.gov.cn/ywzl/gjgnhz/jkzl/"; 
	$ch = curl_init(); 
	curl_setopt ($ch, CURLOPT_URL, $url); 
	curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
	curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,20); 
	$content = curl_exec($ch); 
	curl_close($ch); 
	$hasAutime=strpos($content,'美国(2014年07月21日'); 
	$hasAu=strpos($content,'美国');//防止没有下载到网页误触发,方法不可取
	
	 if (!$hasAutime && $hasAu){
	  require 'mail/mySendMail.php';
	  
	  $subject="内容有更新";
	  $body="内容有更新,请访问<a href='http://www.cnca.gov.cn/ywzl/gjgnhz/jkzl/'>http://www.cnca.gov.cn/ywzl/gjgnhz/jkzl/</a>";
	  if(mySendMail("[email protected]","name",$subject,$body)){
				 echo "有更新,已发送邮件提醒";
		 } else {
				 echo "有更新,邮件发送失败";
		 }
		 die('process abort');
	 } else {
		 echo "not modified";
	 }
	
	sleep($interval);
}while(true);
?>
分類
程序

qpython3

qpython3是一个能在安卓手机上执行python3脚本的软件,很好用。通过SL4A(qpython3已内置),可以方便的编写出实用的安卓脚本程序。

https://github.com/pggdt/loc/tree/master/qpython3-cn这个是我用python3写的一个获取并保存地理位置的小程序。用到的有SL4A中location部分,webview部分,python3中的urllib等,最后用了下bootstrap美化。

分類
程序

把照片重命名为拍摄时间

主要问题就是获取照片的EXIF信息中的拍摄时间。Java的话推荐Drew Noakes的metadata-extractor。python3用Pillow就行了。另外还有一个好用的python3库可以获取exif信息,EXIF.py Python3 port,短小精悍可以用在qpython3上。

实现了下java,成品和源码都在https://github.com/pggdt/rename-JPG-to-Date。先基于后缀名判断下是否是jpg文件,然后有exif信息的重命名为“年年月月日日-时时分分秒秒”格式,如果同一秒还有照片就在文件名后加1。如果勾选了重命名为最后修改时间,则会继续重命名没有exif信息的照片,将它们的名字改为图片的最后修改日期。

分類
程序

Eclipse用法

我是在ubuntu12.04上用的adt-bundle,安装好Sun Java后解压就可以使用了。关于ubuntu12.04上安装Sun Java,参考Ubuntu安装SunJava

为Eclipse安装WindowBuilder

In order to install WindowBuilder on Eclipse 4.3 (Kepler) Modeling let’s click on Help -> Install New Software… and choose (into “Work with:” field ) the main Kepler Update Site (http://download.eclipse.org/releases/kepler), expand the Category “General Purpose Tools” (make sure that “Group items by Category” flag be selected) and choose the following items:

  • SWT Designer
  • SWT Designer Core
  • WindowBuilder Core
  • WindowBuilder Core UI
  • WindowBuilder GroupLayout Support
  • WindowBuilder Java Core

Then press the Next button and follow the wizard until it asks to restart Eclipse. Let’s accept pressing Restart Now button. If you download instead the package Eclipse 4.3 (Kepler) for RCP and RAP Developers WindowBuilder is included.

分類
程序

github用法小记

github还是挺复杂的,记录下免得下次还得搜。首先按照官方文档在网页上建好项目,本地进入对应目录初始化号帐号。然后添加remote:git remote add origin_loc https://github.com/pggdt/项目名.git。然后git pull origin_loc master同步一下。最后将本地的修改提交到github:git commit可以查看本地修改过的文件。git add 文件名,可以添加等下要上传的文件。添加后再用git commit为修改做评价。最后git push origin_loc master就提交完成了。

我就是这么做的,不保证是最正确的做法,有更好意见的请提出来。

網頁註冊賬號,本地安裝git。如果想使用SSH鑒權,秩序把本機的~/.ssh/id_rsa.pub文件內容添加到https://github.com/settings/keys即可。進入要存放項目的目錄,執行git clone [email protected]:pggdt/ulogger-server.git克隆github上的項目到本地。創建cn分支來實現自己的feature git checkout -b cn。然後通過編輯器編輯代碼,完成後通過git status查看變化的文件。通過git add changedFile 來添加文件。通過 git commit -m "更新內容"來提交更新。最後推送到github上git push origin cn。

本文更新於 2018/01/25。

分類
程序

python3批量下图

又发现一个图集,用python3抓下:

import urllib.request def main(): url='http://cdn.test.com/downloads/character' path='/home/me/Pictures/paper/paper-' for i in range(1,400): ii='' if i<10: ii="00"+str(i) elif i<100: ii="0"+str(i) else: ii=str(i) url=url+ii+".jpg" print (url) h='' try: doc=urllib.request.urlopen(url) h=str(doc.info()) except urllib.error.HTTPError: print(ii+'is not exist') if('jpeg' in h): path=path+ii+".jpg" data = urllib.request.urlopen(url).read() f = open(path,"wb") f.write(data) f.close() path='/home/me/Pictures/paper/paper-' print (str(ii)+"OK") url='http://cdn.test.com/downloads/character' if __name__ == "__main__": main()[/code]

有两点改变,python2 import的是urllib,这里用到urlopen,需要import urllib.request。还有就file已经不用了,换成open就好了。getheader函数也没有了。可以对比下python2版本的另一篇python批量下图

分類
程序

python批量下图

有个网站图片很好看,网址也很有规律,但是有的是空链接。用python都下下来了。

import urllib
def main():
  url='http://static.host.com/wallpapers/picture-'
  path='/home/me/Pictures/wallpaper/picture-'
  for i in range(0,400):
    url=url+str(i)+".jpg"
    print url
    doc=urllib.urlopen(url)
    type=doc.info().getheader('Content-Type')
    if(type.find('jpeg')!=-1):
      path=path+str(i)+".jpg"
      data=urllib.urlopen(url).read()
      f=file(path,"wb")  
      f.write(data)  
      f.close()
      path='/home/me/Pictures/wallpaper/picture-'
      print str(i)+"OK"
    url='http://static.host.com/wallpapers/picture-'

if __name__ == "__main__":
  main()

本文更新於 2014/05/26。