杨培文

Yang Peiwen

解决方法:

1
ssh-keygen -R ypw.hk

1
2
3
4
5
6
7
8
9
10

nano /etc/apt/sources.list

# deb http://mirrors.ustc.edu.cn/raspbian/raspbian/ wheezy main contrib non-free rpi
deb http://mirrors.ustc.edu.cn/archive.raspberrypi.org/debian/ wheezy main
deb-src http://mirrors.ustc.edu.cn/raspbian/raspbian/ wheezy main contrib non-free rpi

apt-get update
apt-get upgrade

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# coding:utf-8
__author__ = 'yangpeiwen'

from urllib2 import *
import socket

def zhongjian(yourstr, leftstr, rightstr):
leftposition = yourstr.find(leftstr)
rightposition = yourstr.find(rightstr, leftposition)
return yourstr[leftposition+len(leftstr):rightposition]
# 取文本中间内容

header = """
Host: xueqiu.com
Connection: keep-alive
Accept: application/json, text/javascript, */*; q=0.01
cache-control: no-cache
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36 QQBrowser/3.0.2613.400
Referer: http://xueqiu.com/S/MON
Accept-Encoding: deflate,sdch
Accept-Language: zh-CN,zh;q=0.8
Cookie: xq_a_token=f04765824325b4fdaf86c559e528bd4322a38873; xq_r_token=88deececc3852b877ed15dd7795761e9a6790ea7; __utmt=1; __utma=1.1891582346.1427038206.1427038206.1427038206.1; __utmb=1.1.10.1427038206; __utmc=1; __utmz=1.1427038206.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
"""

def addheader(irequest, iheader):
iheaders = iheader.split("\n")
for iheader1 in iheaders:
iheader2 = iheader1.split(":")
try:
irequest.add_header(iheader2[0], iheader2[1])
except:
pass
# 添加Header防止网站反爬虫

asd = "http://xueqiu.com/statuses/stock_timeline.json?symbol_id=MON&count=200&page=1"
url = Request(asd) # 创建一个urllib2里面的Request,这个request可以伪造HTTP头
addheader(url, header)
socket.setdefaulttimeout(10)

html = urlopen(url).read()
html = html.replace("false", "False")
html = html.replace("true", "True")
html = html.replace("null", "None")
# 将javascript的false等,转为python的False
print html
urls = ""
exec("urls = "+html) # 开挂直接把文本转成python里的变量
ilists = urls['list'] # 文章都在list理=里面
for ilist in ilists:
if ilist['title']: # title可能为None
link = zhongjian(ilist['text'].decode('utf-8'), '>', '<') #寻找链接
print ilist['title'], "----", link

首先是简单的拍照功能,通过下面的php可以实现远程查看照片

1
2
3
4
5
6

<?php
echo shell_exec("raspistill -t 1 -o /home/pi/www/a.jpg -w 2592 -h 1944");
echo '<img style="width: 80%" src=a.jpg>';
?>

如果出错需要执行下面的代码:

1
2
3

chmod a+rw /dev/vchiq

来自:http://www.raspbian.org/RaspbianQuake3

然后,是C语言写的定时拍照器,一分钟一张照片

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
while(1)
{
char cmd[100];
sprintf(cmd, "raspistill -t 1 -o /home/pi/www/img/%d.jpg -w 1920 -h 1080", $
system(cmd);
printf(cmd);
printf("\n");
sleep(60);
}
}


然后我们可以通过gcc编译并执行:

1
2
3
4

gcc paizhao.c
./a.out

但是呢,我们如果关闭putty,拍照就会停止,所以我们需要一个叫screen的东西

1
2
3
4

screen -S "ypw"
./a.out

执行上面的代码之后,关闭putty也会自动拍照了.

然后有了那么多照片之后,怎么样去查看呢?

那么我们就需要一个php遍历文件了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

<!DOCTYPE html>
<html lang="zh-CN">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>拍的照片们</title>
<?php
$dir=dirname(__FILE__);
$files = scandir($dir);
foreach($files as $file)
{
if(strpos($file,".jpg"))
{
echo '<img style="width:80%" src='.$file.'><br>';
$time=filemtime($file);
echo "文件名:$file 拍摄时间:".date("Y-m-d H:i:s",$time)."<br>\n";
}
}
?>

然后保存到/home/pi/www/img文件夹下,这样访问http://192.168.191.3/img/的时候就会返回所有的照片.

拍了一天之后,照片有一千多张,访问刚才那个页面之后内存会崩溃,这样我们就没办法去查看图片了,这时候就需要python来帮忙下载了.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

__author__ = 'lucky dog'

from bs4 import BeautifulSoup
from urllib import *
import os

url = "http://192.168.191.3/img/"

html = urlopen(url).read()
soup = BeautifulSoup(html)
imgs = soup.findAll("img")
for img in imgs:
print img['src']
url2 = "http://192.168.191.3/img/"+img['src']
filepath = "img/"+img['src']
if not os.path.exists(filepath):
urlretrieve(url2.encode('utf-8'), filepath)

这样图片就都下载下来了.

下面这几张图片就是树莓派和我的植物

之后我觉得晚上都是黑色的图片多无聊,我就加了个灯

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

# coding:utf-8
__author__ = 'Administrator'

from urllib import *
from bs4 import BeautifulSoup
import socket
import threading
import Queue
import time

url = 'http://libopac.btbu.edu.cn:8080/opac/browseByCategory?pager.offset='
socket.setdefaulttimeout(3) # 3秒超时
maxnum = 634309 # 图书总数
print "\n"

q = Queue.Queue() # 构造一个队列,它可以put入任务和get出任务,先进先出
# 比如放入1,2,3,4,5 则你取出来的时候也是取出来1,2,3,4,5这样的顺序
f = open('library3.txt', 'a')

def getlinks():
# 线程1,获取链接的线程
offset = 192850 # 调这个值可以断点续传
while offset < maxnum:
try:
html = urlopen(url + str(offset)).read().decode('utf-8')
soup = BeautifulSoup(html)
links = soup.findAll(target='_blank') # 寻找所有的链接
onetask = (offset, links) # 构建一个(offset, links)结构作为task,其实就是(下到第几本书了, 链接们是什么)
q.put(onetask) # 放入queue中
offset += 25
print "\r" + str(offset) + "/" + str(maxnum) + " " + str(offset * 100.0 / maxnum) + "% 第" + str(
offset / 25) + "页----获取列表"
except IOError:
# print 'timeout'
pass
except Exception, e:
print e

class MyThread(threading.Thread):
def __init__(self, queue):
threading.Thread.__init__(self)
self.queue = queue # 初始化构造函数,传入queue

def run(self):
while True:
myonetask = self.queue.get() # 获取任务
myoffset, mylinks = myonetask # 解析任务
print "\r" + str(myoffset) + "/" + str(maxnum) + " " + str(myoffset * 100.0 / maxnum) + "% 第" \
+ str(myoffset / 25) + "页----收到任务"
mywritecontent = ""
for mylink in mylinks:
always = True # 建立一个循环下载,
while always:
try:
myurl2 = 'http://libopac.btbu.edu.cn:8080' + mylink['href']
# print link.text, url2
mywritecontent += myurl2.encode('utf-8', 'ignore') + "\n"
mywritecontent += mylink.text.encode('utf-8', 'ignore') + "\n"
# 标题信息和内容
myhtml2 = urlopen(myurl2).read()
mysoup2 = BeautifulSoup(myhtml2)
mywritecontent += mysoup2.find(id='detailsTable').text.encode('utf-8', 'ignore') + "\n"
# 获得馆藏信息 getHoldingsInformation
myjson3 = urlopen(myurl2.replace('book', 'book/getHoldingsInformation')).read()
mywritecontent += myjson3 + "\n\n"
always = False # 下载成功之后才取消循环
except IOError:
pass # 如果是IOError就是超时了,pass掉(相当于C++的;空语句)
except Exception:
# 为了防止某些失效链接,我们将跳过失败的书籍
# 比如http://libopac.btbu.edu.cn:8080/opac/book/627232
always = False
print "\r" + str(myoffset) + "/" + str(maxnum) + " " + str(myoffset * 100.0 / maxnum) + "% 第" \
+ str(myoffset / 25) + "页----下载完成----" + str(myoffset + 25)
mywritecontent += "\n==========第" + str(myoffset / 25) + "页==========\n\n"
f.write(mywritecontent)
f.flush() # 写出到文件
time.sleep(0.01) # 线程累了 休息一下

t1 = threading.Thread(target=getlinks) # 获取链接的线程
t1.start()

for asd in range(10):
t2 = MyThread(q) # 从队列里下载数据的线程
t2.start()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# coding:utf-8
__author__ = 'yangpeiwen'

from urllib import *
from bs4 import BeautifulSoup
import socket
import os

url = "http://wap.jdxs.net/index.php/book/chapter/bid=100722/cid=16819732/"
socket.setdefaulttimeout(3)
path = "xs"

socket.setdefaulttimeout(3) # 3秒超时
if os.path.exists(path) is False:
os.makedirs(path)
# 如果没有这个文件夹就创建一个
f = open(path+"/xs.txt", "w")

always = True
while always:
ci = 0
try:
html = urlopen(url).read()
soup = BeautifulSoup(html)
text = soup.find(attrs={'class': 'chapter'}).text
print text
f.write(text.encode("utf-8"))
if soup.find(id='btnNext').text.encode('utf-8').index('下一章') == 0:
url = "http://wap.jdxs.net/" + soup.find(id='btnNext')['href']
print url
else:
break
except IOError:
ci += 1
if ci > 10:
always = False
f.close()

https://github.com/ypwhs/creatBarCode

核心代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157

//
// ViewController.swift
// creatBarCode
//
// Created by 杨培文 on 15/3/13.
// Copyright (c) 2015年 杨培文. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

var Aji = ["0001101", "0011001", "0010011", "0111101", "0100011",
"0110001" ,"0101111", "0111011", "0110111", "0001011"]
var Bji = ["0100111", "0110011", "0011011", "0100001", "0011101",
"0111001" ,"0000101", "0010001", "0001001", "0010111"]
var Cji = ["1110010", "1100110", "1101100", "1000010", "1011100",
"1001110" ,"1010000", "1000100", "1001000", "1110100"]
var start = "101"
var fenge = "01010"

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

@IBOutlet weak var numbertext: UITextField!
@IBOutlet weak var outtext: UITextView!
@IBAction func creat(sender: AnyObject) {
var mynumber = numbertext.text

if countElements(mynumber) != 11{
outtext.text = "长度有误"
println(mynumber)
}else{
var a = [unichar](count:11,repeatedValue:0x0)
(mynumber as NSString).getCharacters(&a, range: NSRange(location: 0,length: 11))
var numbers = [0]
for i in 0..<11{
numbers += [Int(a[10-i] - 48)]
}
numbers += [6]

println(a)

var text = "开始生成\n目标数字:6"+numbertext.text

//生成检验码
var c1 = numbers[12]+numbers[10]+numbers[8]
c1+=numbers[6]+numbers[4]+numbers[2]
var c2 = numbers[11]+numbers[9]+numbers[7]
c2+=numbers[5]+numbers[3]+numbers[1]
var verify = 10-(c1 + c2*3)%10
if verify == 10{
verify = 0
}
println(verify)
numbers[0] = verify
text += String(verify) + "\n"

//生成条码
var barcode = start
barcode += Aji[numbers[11]]
barcode += Bji[numbers[10]]
barcode += Bji[numbers[9]]
barcode += Bji[numbers[8]]
barcode += Aji[numbers[7]]
barcode += Aji[numbers[6]]
barcode += fenge
barcode += Cji[numbers[5]]
barcode += Cji[numbers[4]]
barcode += Cji[numbers[3]]
barcode += Cji[numbers[2]]
barcode += Cji[numbers[1]]
barcode += Cji[numbers[0]]
barcode += start

text += "编码后:\n" + start + " "
text += Aji[numbers[11]] + " "
text += Bji[numbers[10]] + " "
text += Bji[numbers[9]] + " "
text += Bji[numbers[8]] + " "
text += Aji[numbers[7]] + " "
text += Aji[numbers[6]] + " "
text += fenge + " "
text += Cji[numbers[5]] + " "
text += Cji[numbers[4]] + " "
text += Cji[numbers[3]] + " "
text += Cji[numbers[2]] + " "
text += Cji[numbers[1]] + " "
text += Cji[numbers[0]] + " "
text += start + "\n"

outtext.text = text

//开始画图
var x:CGFloat = 0
bar.image = UIImage()
var context = UIGraphicsGetCurrentContext()
UIGraphicsBeginImageContext(bar.frame.size);
bar.image?.drawInRect(CGRectMake(0, 0, bar.frame.size.width, bar.frame.size.height))
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 2.0);
CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), true);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0); //颜色
CGContextBeginPath(UIGraphicsGetCurrentContext());

for i in barcode{
if i == "1"{
var xx = x*2+10
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), xx, 0);//起点
if (x<3)|((x>6*7+3)&(x<6*7+3+5))|(x>12*7+5+2){
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), xx, 110);//终点
}else{
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), xx, 100);//终点
}
CGContextStrokePath(UIGraphicsGetCurrentContext());
}
x += 1
}
bar.image=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

//修改下面的文字
var c = "6 "
c += String(numbers[11])+" "
c += String(numbers[10])+" "
c += String(numbers[9])+" "
c += String(numbers[8])+" "
c += String(numbers[7])+" "
c += String(numbers[6])+" "
c += " "
c += String(numbers[5])+" "
c += String(numbers[4])+" "
c += String(numbers[3])+" "
c += String(numbers[2])+" "
c += String(numbers[1])+" "
c += String(numbers[0])+" "
codenumber.text = c
}
}

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
numbertext.resignFirstResponder()
}

@IBOutlet weak var bar: UIImageView!
@IBOutlet weak var codenumber: UILabel!

}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

<?php
include("config.php");
$username = $_GET['username'];
$con = mysql_connect(MYSQL_IP.':'.MYSQL_PORT,MYSQL_USER,MYSQL_PSWD);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}else
{
mysql_select_db("ypw", $con);
mysql_query("SET NAMES UTF8");
$result = mysql_query("SELECT * FROM `users` WHERE `username` = '$username';");
$row = mysql_fetch_array($result);
echo $row['password'];
mysql_close($con);
}
?>

http://xxx.com/login.php?username=ypw

其中的最大处理器状态可以凭自己的感觉设置,一般来说有电源的情况下可以高一点,用电池的时候可以设置更低,我在35%状态下上网页看电影都是一点都不卡的.如果你需要更高的速度,则可以调到高性能模式.

一般情况下不需要调这个模式,因为发热.

0%