From bbb4453d1a38d4cf5c89524ee8cc6e082d67d7d3 Mon Sep 17 00:00:00 2001 From: gaoxingang <546657868@qq.com> Date: Tue, 26 Feb 2019 12:22:26 +0800 Subject: [PATCH 1/2] run --- ...34\347\250\213\345\274\200\346\234\272.py" | 33 ++++++++++++------- countFile.py | 2 ++ douban_book.py | 5 +-- douban_movie.py | 4 +-- excelToDatabase.py | 11 +++---- lagouSpider.py | 1 + qiubai_crawer.py | 10 ++++-- readExcel.py | 6 ++-- .../lagou.py" | 10 ++++-- .../meizitu.py" | 4 +++ .../qiubai_crawer.py" | 10 ++++-- 11 files changed, 66 insertions(+), 30 deletions(-) diff --git "a/Python \351\273\221\351\255\224\346\263\225/Python \350\277\234\347\250\213\345\274\200\346\234\272.py" "b/Python \351\273\221\351\255\224\346\263\225/Python \350\277\234\347\250\213\345\274\200\346\234\272.py" index 1b23c160..66d52b24 100644 --- "a/Python \351\273\221\351\255\224\346\263\225/Python \350\277\234\347\250\213\345\274\200\346\234\272.py" +++ "b/Python \351\273\221\351\255\224\346\263\225/Python \350\277\234\347\250\213\345\274\200\346\234\272.py" @@ -1,9 +1,16 @@ -def wake_up(request, mac='DC-4A-3E-78-3E-0A'): +# -*- coding: utf-8 -*- +import time +import socket +import struct +import requests +import os + +def wake_up(broadcast='192.168.0.255', mac='DC-4A-3E-78-3E-0A'): MAC = mac - BROADCAST = "192.168.0.255" + BROADCAST = broadcast if len(MAC) != 17: raise ValueError("MAC address should be set as form 'XX-XX-XX-XX-XX-XX'") - mac_address = MAC.replace("-", '') + mac_address = MAC.replace(":", '') data = ''.join(['FFFFFFFFFFFF', mac_address * 20]) # 构造原始数据格式 send_data = b'' @@ -16,13 +23,17 @@ def wake_up(request, mac='DC-4A-3E-78-3E-0A'): try: sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) - sock.sendto(send_data, (BROADCAST, 7)) - time.sleep(1) - sock.sendto(send_data, (BROADCAST, 7)) - time.sleep(1) - sock.sendto(send_data, (BROADCAST, 7)) - return HttpResponse() + # sock.sendto(send_data, (BROADCAST, 7)) + # time.sleep(1) + # sock.sendto(send_data, (BROADCAST, 7)) + # time.sleep(1) + # sock.sendto(send_data, (BROADCAST, 7)) + + sock.sendto('shutdown -s -t 00', (BROADCAST, 7)) + print("Done") except Exception as e: - return HttpResponse() - print(e) \ No newline at end of file + print(e) + +if __name__ == "__main__": + wake_up('127.0.0.1','88:e9:fe:6d:57:16') \ No newline at end of file diff --git a/countFile.py b/countFile.py index de22f100..55cd73c2 100644 --- a/countFile.py +++ b/countFile.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import os result = [] def get_all(cwd): @@ -13,4 +14,5 @@ def get_all(cwd): if __name__ == "__main__": cur_path = os.getcwd() #当前目录 + cur_path = '/tmp/gxg' get_all(cur_path) \ No newline at end of file diff --git a/douban_book.py b/douban_book.py index 53350450..e5828dd4 100644 --- a/douban_book.py +++ b/douban_book.py @@ -1,10 +1,11 @@ +# -*- coding: utf-8 -*- from bs4 import BeautifulSoup import requests from openpyxl import Workbook -excel_name = "书籍.xlsx" +excel_name = u"书籍.xlsx" wb = Workbook() ws1 = wb.active -ws1.title='书籍' +ws1.title=u'书籍' def get_html(url): diff --git a/douban_movie.py b/douban_movie.py index 887c1411..290d04f4 100644 --- a/douban_movie.py +++ b/douban_movie.py @@ -6,9 +6,9 @@ from bs4 import BeautifulSoup from openpyxl import Workbook wb = Workbook() -dest_filename = '电影.xlsx' +dest_filename = u'电影.xlsx' ws1 = wb.active -ws1.title = "电影top250" +ws1.title = u"电影top250" DOWNLOAD_URL = 'http://movie.douban.com/top250/' diff --git a/excelToDatabase.py b/excelToDatabase.py index 215598fd..3625e8ba 100644 --- a/excelToDatabase.py +++ b/excelToDatabase.py @@ -1,7 +1,7 @@ from openpyxl import load_workbook import pymysql config = { - 'host': '127.0.0.1', + 'host': '192.168.22.2', 'port':3306, 'user': 'root', 'password': 'root', @@ -13,17 +13,16 @@ conn.autocommit(1) cursor = conn.cursor() name = 'lyexcel' -cursor.execute('create database if not exists %s' %name) +# cursor.execute('create database if not exists %s' %name) conn.select_db(name) -table_name = 'info' -cursor.execute('create table if not exists %s(id MEDIUMINT NOT NULL AUTO_INCREMENT,name varchar(30),tel varchar(30),primary key (id))'%table_name) +# table_name = 'info' +# cursor.execute('create table if not exists %s(id MEDIUMINT NOT NULL AUTO_INCREMENT,name varchar(30),tel varchar(30),primary key (id))'%table_name) wb2 = load_workbook('hpu.xlsx') ws=wb2.get_sheet_names() for row in wb2: - print("1") for cell in row: - value1=(cell[0].value,cell[4].value) + value1=(cell[0].value,cell[1].value) cursor.execute('insert into info (name,tel) values(%s,%s)',value1) print("overing...") diff --git a/lagouSpider.py b/lagouSpider.py index 8432ce66..df2d31a8 100644 --- a/lagouSpider.py +++ b/lagouSpider.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import requests from openpyxl import Workbook diff --git a/qiubai_crawer.py b/qiubai_crawer.py index e37e7e7d..b6aea88b 100644 --- a/qiubai_crawer.py +++ b/qiubai_crawer.py @@ -1,6 +1,11 @@ +# -*- coding: utf-8 -*- import requests from bs4 import BeautifulSoup +import sys +import io +reload(sys) +sys.setdefaultencoding('utf8') def download_page(url): headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0"} @@ -38,8 +43,9 @@ def get_content(html, page): def save_txt(*args): for i in args: - with open('qiubai.txt', 'a', encoding='utf-8') as f: - f.write(i) + with io.open('qiubai.txt', 'a', encoding='utf-8') as f: + str = i.decode('utf-8') + f.write(str) def main(): diff --git a/readExcel.py b/readExcel.py index 147d2434..e7c601a6 100644 --- a/readExcel.py +++ b/readExcel.py @@ -1,6 +1,6 @@ +# -*- coding: utf-8 -*- from openpyxl import Workbook -from openpyxl.compat import range -from openpyxl.cell import get_column_letter +from openpyxl.utils import get_column_letter wb = Workbook() dest_filename = 'empty_book2.xlsx' ws1 = wb.active # 第一个表 @@ -13,5 +13,5 @@ ws3 = wb.create_sheet(title="Data") for row in range(10, 20): for col in range(27, 54): - _ = ws3.cell(column=col, row=row, value="%s" % get_column_letter(col)) + ws3.cell(column=col, row=row, value="%s" % get_column_letter(col)) wb.save(filename=dest_filename) diff --git "a/\347\210\254\350\231\253\351\233\206\345\220\210/lagou.py" "b/\347\210\254\350\231\253\351\233\206\345\220\210/lagou.py" index e0982308..223db3e9 100644 --- "a/\347\210\254\350\231\253\351\233\206\345\220\210/lagou.py" +++ "b/\347\210\254\350\231\253\351\233\206\345\220\210/lagou.py" @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import random import time @@ -5,13 +6,18 @@ from openpyxl import Workbook import pymysql.cursors +import sys + +reload(sys) +sys.setdefaultencoding('utf8') + def get_conn(): '''建立数据库连接''' - conn = pymysql.connect(host='localhost', + conn = pymysql.connect(host='192.168.22.2', user='root', password='root', - db='python', + db='test', charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) return conn diff --git "a/\347\210\254\350\231\253\351\233\206\345\220\210/meizitu.py" "b/\347\210\254\350\231\253\351\233\206\345\220\210/meizitu.py" index 4f6932db..ef2bffec 100644 --- "a/\347\210\254\350\231\253\351\233\206\345\220\210/meizitu.py" +++ "b/\347\210\254\350\231\253\351\233\206\345\220\210/meizitu.py" @@ -1,9 +1,13 @@ +# -*- coding: utf-8 -*- import requests import os import time import threading from bs4 import BeautifulSoup +import sys +reload(sys) +sys.setdefaultencoding('utf8') def download_page(url): ''' diff --git "a/\347\210\254\350\231\253\351\233\206\345\220\210/qiubai_crawer.py" "b/\347\210\254\350\231\253\351\233\206\345\220\210/qiubai_crawer.py" index e37e7e7d..9d41a93c 100644 --- "a/\347\210\254\350\231\253\351\233\206\345\220\210/qiubai_crawer.py" +++ "b/\347\210\254\350\231\253\351\233\206\345\220\210/qiubai_crawer.py" @@ -1,6 +1,11 @@ +# -*- coding: utf-8 -*- import requests from bs4 import BeautifulSoup +import sys +import io +reload(sys) +sys.setdefaultencoding('utf8') def download_page(url): headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0"} @@ -38,8 +43,9 @@ def get_content(html, page): def save_txt(*args): for i in args: - with open('qiubai.txt', 'a', encoding='utf-8') as f: - f.write(i) + with io.open('qiubai.txt', 'a', encoding='utf-8') as f: + str = i.decode(i) + f.write(str) def main(): From 56105e3eb36d629644b2e8857ab387650f388136 Mon Sep 17 00:00:00 2001 From: gaoxingang <546657868@qq.com> Date: Tue, 26 Feb 2019 22:46:03 +0800 Subject: [PATCH 2/2] machine count --- machine-count.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 machine-count.py diff --git a/machine-count.py b/machine-count.py new file mode 100644 index 00000000..92b04ac6 --- /dev/null +++ b/machine-count.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +import requests +import json + +def dealJson(url): + header = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0'} + json = requests.get(url, headers=header).content + return json + +if __name__ == '__main__': + + jsonStr = dealJson('') + text = json.loads(jsonStr) + + print len(text['data']) +