Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions fybhp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.idea
fortest.py
*.png
*.jpg
migrations
*.sqlite
*.pyc
20 changes: 20 additions & 0 deletions fybhp/practice0/practice0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding:utf-8 -*-
import PIL
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw

#设置字体,如果没有,也可以不设置
#font = ImageFont.truetype("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf",13)

#打开底版图片
imageFile = "./icon.jpg"
im1=Image.open(imageFile)

# 在图片上添加文字 1
draw = ImageDraw.Draw(im1)
draw.text((90, 5),"2",(255,0,0))#,font=font)
draw = ImageDraw.Draw(im1)

# 保存
im1.save("./practice1/icon.png")
22 changes: 22 additions & 0 deletions fybhp/practice1/practice1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding:utf-8 -*-
import re
import string
import random

map = {}
#pattern = re.compile(r'([a-z0-9A-Z]{4}-){3}([a-z0-9A-Z]{4})')
#这个函数定义的很精髓
def id_generator(size=4, chars=string.ascii_uppercase + string.digits + string.ascii_lowercase):
#[random.choice(chars) for _ in range(size)]为列表解析
#(random.choice(chars) for _ in range(size))为生成器,其对内存更友好
list = []
for i in range(4):
a = ''.join(random.choice(chars) for _ in range(size))
list.append(a)
return list
for i in range(200):
id = '-'.join(id_generator())
while id in map.values():
id = '-'.join(id_generator())
map[i] = id
print map
Binary file added fybhp/practice10/arial.ttf
Binary file not shown.
25 changes: 25 additions & 0 deletions fybhp/practice10/practice10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding:utf-8 -*-
import string
import random
from PIL import Image,ImageDraw,ImageFont,ImageFilter

def numgenerator(size=4, chars=string.ascii_uppercase + string.digits + string.ascii_lowercase):
return ''.join(random.choice(chars) for _ in range(size))

def getcolor():
return (random.randint(0,255),random.randint(0,255),random.randint(0,255))

def getfont():
font = ImageFont.truetype('Arial.ttf',random.randint(50,65))
return font

check = numgenerator()
imageFile = "./bacdgroud.jpg"
img = Image.open(imageFile)
draw = ImageDraw.Draw(img)
for i in range(4):
draw.text((72*i+random.randint(15,20), random.randint(5,10)),check[i],getcolor(),font=getfont())
draw = ImageDraw.Draw(img)
image = img.filter(ImageFilter.BLUR)

image.save("./test1.jpg")
11 changes: 11 additions & 0 deletions fybhp/practice11/filter_words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
����
����Ա
����Ա
�쵼
ţ��
ţ��
����
����
love
sex
jiangge
12 changes: 12 additions & 0 deletions fybhp/practice11/practice11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding:utf-8 -*-

list = []
file = open('filter_words.txt','r')
content = file.read().decode('gbk')
allwords = content.split()
#print allwords
checkword = raw_input('>').decode('utf-8')
if checkword in allwords:
print 'Freedom'
else:
print 'Hunam Rights'
11 changes: 11 additions & 0 deletions fybhp/practice12/filter_words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
����
����Ա
����Ա
�쵼
ţ��
ţ��
����
����
love
sex
jiangge
12 changes: 12 additions & 0 deletions fybhp/practice12/practice12.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding:utf-8 -*-
import re
list = []
file = open('filter_words.txt','r')
content = file.read().decode('gbk')
allwords = content.split()
#print allwords
yourword = raw_input('>').decode('utf-8')
for mingan in allwords:
if mingan in yourword:
yourword = re.sub(mingan,'*'*len(mingan),yourword)
print yourword
Empty file.
17 changes: 17 additions & 0 deletions fybhp/practice13/practice13/items.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-

# Define here the models for your scraped items
#
# See documentation in:
# http://doc.scrapy.org/en/latest/topics/items.html

import scrapy


class Practice13Item(scrapy.Item):
# define the fields for your item here like:
# name = scrapy.Field()
image_urls = scrapy.Field()
images = scrapy.Field()
image_paths = scrapy.Field()
pass
21 changes: 21 additions & 0 deletions fybhp/practice13/practice13/pipelines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
import scrapy
from scrapy.pipelines.images import ImagesPipeline
from scrapy.exceptions import DropItem
# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html


class Practice13Pipeline(ImagesPipeline):
def get_media_requests(self, item, info):
for image_url in item['image_urls']:
yield scrapy.Request(image_url)

def item_completed(self, results, item, info):
image_paths = [x['path'] for ok, x in results if ok]
if not image_paths:
raise DropItem("Item contains no images")
item['image_paths'] = image_paths
return item
87 changes: 87 additions & 0 deletions fybhp/practice13/practice13/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# -*- coding: utf-8 -*-

# Scrapy settings for practice13 project
#
# For simplicity, this file contains only settings considered important or
# commonly used. You can find more settings consulting the documentation:
#
# http://doc.scrapy.org/en/latest/topics/settings.html
# http://scrapy.readthedocs.org/en/latest/topics/downloader-middleware.html
# http://scrapy.readthedocs.org/en/latest/topics/spider-middleware.html

BOT_NAME = 'practice13'

SPIDER_MODULES = ['practice13.spiders']
NEWSPIDER_MODULE = 'practice13.spiders'

ITEM_PIPELINES = {'practice13.pipelines.Practice13Pipeline': 1}

IMAGES_STORE = '.'
# Crawl responsibly by identifying yourself (and your website) on the user-agent
#USER_AGENT = 'practice13 (+http://www.yourdomain.com)'

# Configure maximum concurrent requests performed by Scrapy (default: 16)
#CONCURRENT_REQUESTS=32

# Configure a delay for requests for the same website (default: 0)
# See http://scrapy.readthedocs.org/en/latest/topics/settings.html#download-delay
# See also autothrottle settings and docs
#DOWNLOAD_DELAY=3
# The download delay setting will honor only one of:
#CONCURRENT_REQUESTS_PER_DOMAIN=16
#CONCURRENT_REQUESTS_PER_IP=16

# Disable cookies (enabled by default)
#COOKIES_ENABLED=False

# Disable Telnet Console (enabled by default)
#TELNETCONSOLE_ENABLED=False

# Override the default request headers:
#DEFAULT_REQUEST_HEADERS = {
# 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
# 'Accept-Language': 'en',
#}

# Enable or disable spider middlewares
# See http://scrapy.readthedocs.org/en/latest/topics/spider-middleware.html
#SPIDER_MIDDLEWARES = {
# 'practice13.middlewares.MyCustomSpiderMiddleware': 543,
#}

# Enable or disable downloader middlewares
# See http://scrapy.readthedocs.org/en/latest/topics/downloader-middleware.html
#DOWNLOADER_MIDDLEWARES = {
# 'practice13.middlewares.MyCustomDownloaderMiddleware': 543,
#}

# Enable or disable extensions
# See http://scrapy.readthedocs.org/en/latest/topics/extensions.html
#EXTENSIONS = {
# 'scrapy.telnet.TelnetConsole': None,
#}

# Configure item pipelines
# See http://scrapy.readthedocs.org/en/latest/topics/item-pipeline.html
#ITEM_PIPELINES = {
# 'practice13.pipelines.SomePipeline': 300,
#}

# Enable and configure the AutoThrottle extension (disabled by default)
# See http://doc.scrapy.org/en/latest/topics/autothrottle.html
# NOTE: AutoThrottle will honour the standard settings for concurrency and delay
#AUTOTHROTTLE_ENABLED=True
# The initial download delay
#AUTOTHROTTLE_START_DELAY=5
# The maximum download delay to be set in case of high latencies
#AUTOTHROTTLE_MAX_DELAY=60
# Enable showing throttling stats for every response received:
#AUTOTHROTTLE_DEBUG=False

# Enable and configure HTTP caching (disabled by default)
# See http://scrapy.readthedocs.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings
#HTTPCACHE_ENABLED=True
#HTTPCACHE_EXPIRATION_SECS=0
#HTTPCACHE_DIR='httpcache'
#HTTPCACHE_IGNORE_HTTP_CODES=[]
#HTTPCACHE_STORAGE='scrapy.extensions.httpcache.FilesystemCacheStorage'
4 changes: 4 additions & 0 deletions fybhp/practice13/practice13/spiders/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This package will contain the spiders of your Scrapy project
#
# Please refer to the documentation for information on how to create and manage
# your spiders.
22 changes: 22 additions & 0 deletions fybhp/practice13/practice13/spiders/shanben.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding:utf-8 -*-
import scrapy
from scrapy.selector import Selector
from practice13.items import Practice13Item

class TiebapicSpider(scrapy.Spider):
name = "shan"
allowed_domains = ["tieba.baidu.com"]
start_urls = ['http://tieba.baidu.com/p/2166231880']

def parse(self,response):
sel = Selector(response)
div1 = sel.xpath('.//div[@class="d_post_content j_d_post_content clearfix"]')
#print div1
for single1 in div1:
div2 = single1.xpath('./img')
#print div2
for single2 in div2:
item = Practice13Item()
item['image_urls'] = [single2.xpath('./@src').extract()[0]]
print item['image_urls']
yield item
11 changes: 11 additions & 0 deletions fybhp/practice13/scrapy.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Automatically created by: scrapy startproject
#
# For more information about the [deploy] section see:
# https://scrapyd.readthedocs.org/en/latest/deploy.html

[settings]
default = practice13.settings

[deploy]
#url = http://localhost:6800/
project = practice13
22 changes: 22 additions & 0 deletions fybhp/practice14/practice14.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding:utf-8 -*-
from xlwt import Workbook
import json

file = open('student.txt','rb')
text = file.read().decode('gbk')
js = json.loads(text)
book = Workbook()
sheet = book.add_sheet('student')
rownum = 0
js2 = sorted(js)
for i in js2:
colnum = 0
print i
sheet.write(rownum,colnum,unicode(i))
for item in js[i]:
print item
colnum += 1
sheet.write(rownum,colnum,unicode(item))
rownum += 1
book.save('student.xls')

5 changes: 5 additions & 0 deletions fybhp/practice14/student.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"1":["����",150,120,100],
"2":["����",90,99,95],
"3":["����",60,66,68]
}
Binary file added fybhp/practice14/student.xls
Binary file not shown.
5 changes: 5 additions & 0 deletions fybhp/practice15/city.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"1" : "�Ϻ�",
"2" : "����",
"3" : "�ɶ�"
}
Binary file added fybhp/practice15/city.xls
Binary file not shown.
17 changes: 17 additions & 0 deletions fybhp/practice15/practice15.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding:utf-8 -*-
from xlwt import Workbook
import json

file = open('city.txt','rb')
text = file.read().decode('gbk')
js = json.loads(text)
book = Workbook()
sheet = book.add_sheet('city')
rownum = 0
js2 = sorted(js)
for i in js2:
colnum = 0
sheet.write(rownum,colnum,unicode(i))
sheet.write(rownum,colnum+1,unicode(js[i]))
rownum += 1
book.save('city.xls')
5 changes: 5 additions & 0 deletions fybhp/practice16/numbers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
[1, 82, 65535],
[20, 90, 13],
[26, 809, 1024]
]
Binary file added fybhp/practice16/numbers.xls
Binary file not shown.
16 changes: 16 additions & 0 deletions fybhp/practice16/practice16.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding:utf-8 -*-
from xlwt import Workbook
import json

file = open('numbers.txt','rb')
text = file.read()
js = json.loads(text)
book = Workbook()
sheet = book.add_sheet('numbers')
rownum = 0
colnum = 0
for i in range(len(js)):
for j in range(len(js[i])):
sheet.write(i,j,str(js[i][j]))
#rownum += 1
book.save('numbers.xls')
Loading