diff --git a/20200206 b/20200206 deleted file mode 100644 index 495099c..0000000 --- a/20200206 +++ /dev/null @@ -1 +0,0 @@ -2020020jenkins diff --git a/README.md b/README.md deleted file mode 100644 index e826503..0000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -# python_test \ No newline at end of file diff --git a/ansible/playbook1.yml b/ansible/playbook1.yml new file mode 100644 index 0000000..b81f2bb --- /dev/null +++ b/ansible/playbook1.yml @@ -0,0 +1,45 @@ +--- + +- hosts: all + user: root + vars_prompt: + - name: http #bianlinag mingc + prompt: please enter something: + private: no #display connect + task: + - name: test action + action: yum name=httpd state=installed #one acion + - name: configure apache + copy: src=files/httpd.conf dest=/etc/httpd/config/httpd.conf #two 模块名 + - name: restart apache + service: + name: httpd + state: restarted #three 格式写法 + tasks: + - name: install memcached + yum: name=memcached state=installed + - name: set memcached size ##设置变量,将内存的4分之1 + set_fact: memcached_size="{{ansible_memtotal_mb/4}}" + - name: templete configure files + templete: src=templete.j2 dest=/etc/foo.configure + notify:#通知必须有,不然handler不会执行 + - restart memcached #调用 + - restart apache + handlers: + - name: restart memcached + service: name=memcached state=restarted + - name: restart apache + service: name=httpd state=restarted + +- hosts: all + user: root + vars: + + task: + - name: stop memcached + service: name=memcached state=stopped + - name: remove memcached + command: rpm -e memcached --nodeps + handlers: + - name: restart memcached + service: name= diff --git a/autodev.py b/autodev.py index 94af499..6a3318a 100644 --- a/autodev.py +++ b/autodev.py @@ -1,63 +1,63 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# @Time : 2017/8/15 14:59 -# @Author : jiayanhua -# @Site : -# @File : autodev.py -# @Software: PyCharm Community Edition -#IPy -''' - -from IPy import IP -#以不同格式展示 -print(IP('192.168.0.0/24').strNormal(0)) -print(IP('192.168.0.0/24').strNormal(1)) -print(IP('192.168.0.0/24').strNormal(2)) -print(IP('192.168.0.0/24').strNormal(3)) -#多网格计算方法,ip段是否叠加 -print IP('10.0.0.0/24') 1: - print ('net:%s' %ips.net()) - print ('netmask:%s' %ips.netmask()) - print ('broadcast:%s' %ips.broadcast()) - print ('reverse address:%s' %ips.reverseNames()[0]) - -''' -#DNS -## A 记录 -import dns.resolver -domain = raw_input('please enter domain : ') -A = dns.resolver.query(domain,'A') #指定查A记录/NS/CNAME -for i in A.response.answer: - for j in i.items: - print j.address - - - - - - +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 2017/8/15 14:59 +# @Author : jiayanhua +# @Site : +# @File : autodev.py +# @Software: PyCharm Community Edition +#IPy +''' + +from IPy import IP +#以不同格式展示 +print(IP('192.168.0.0/24').strNormal(0)) +print(IP('192.168.0.0/24').strNormal(1)) +print(IP('192.168.0.0/24').strNormal(2)) +print(IP('192.168.0.0/24').strNormal(3)) +#多网格计算方法,ip段是否叠加 +print IP('10.0.0.0/24') 1: + print ('net:%s' %ips.net()) + print ('netmask:%s' %ips.netmask()) + print ('broadcast:%s' %ips.broadcast()) + print ('reverse address:%s' %ips.reverseNames()[0]) + +''' +#DNS +## A 记录 +import dns.resolver +domain = raw_input('please enter domain : ') +A = dns.resolver.query(domain,'A') #指定查A记录/NS/CNAME +for i in A.response.answer: + for j in i.items: + print j.address + + + + + + diff --git a/ben-11.py b/ben-11.py new file mode 100644 index 0000000..e673ccc --- /dev/null +++ b/ben-11.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# print "+++++++++++++11+++++++++++++++" +# print "How old are you?", +# age=raw_input() +# print "How tall are you ?", +# height=raw_input() +# print "How much are you weight?", +# weight=raw_input() +# +# print "So you's %r old,%r tall and %r heavy"%(age,height,weight) +# +# nId='' +# while 1: +# nId=raw_input("Input you id plz") +# if len(nId) != len("1223213123123******"): +# print 'wring length of id' +# else: +# break +# +# print 'you id is %s'%(nId) +# +# #int +# nAge=int(raw_input("input you age plz:\n")) +# if nAge > 0 and nAge < 120: +# print 'thanks!' +# else: +# print 'bad age' +# print 'you age is %d\n'%nAge +# +# #flat +# fweight=0.0 +# fweight=float(raw_input('input you weight\n')) +# print 'your weight is %f'%fweight + + +print "++++++++++++++++12++++++++++++++++++" +age=raw_input("how age you ?") +weight=raw_input("how are you weight") +height=raw_input("how are you height") +print "so you age %r,height %r ,weight %r"%(age,weight,height) \ No newline at end of file diff --git a/check_port.py b/check_port.py index c3f944b..d995e42 100644 --- a/check_port.py +++ b/check_port.py @@ -1,3 +1,3 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -#one +#!/usr/bin/env python +# -*- coding: utf-8 -*- +#one diff --git a/checkdns.py b/checkdns.py index df5cd8f..72348f0 100644 --- a/checkdns.py +++ b/checkdns.py @@ -1,50 +1,50 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# @Time : 2017/8/15 19:43 -# @Author : jiayanhua -# @Site : -# @File : checkdns.py -# @Software: PyCharm Community Edition -#定义域名, -#解析域名获取ip,多个ip访问list中 -#对ip进行http检测 -import dns.resolver -import httplib -import os - -iplist = [] -appdomain = "www.qq.com" - -def get_doaminip(domain=""): - try: - ips=dns.resolver.query(domain,'A') - except Exception,e: - print " resolver is error:"+ str(e) - return - for i in ips.response.answer: - for j in i.items: - iplist.append(j.address) - return True -def checkip(ip): - checkurl = ip + ":80" - #print checkurl - getcontent = "" - httplib.socket.setdefaulttimeout(5) - conn = httplib.HTTPConnection(checkurl) - try: - conn.request("GET","/",headers={"Host":appdomain}) #发起url请求 - r = conn.getresponse() - getcontent = r.read(15) - #print getcontent - finally: - if getcontent == "": - print ip +"[ok]" - else: - print ip + "[error]" -if __name__ == "__main__": - #print iplist - if get_doaminip(appdomain) and len(iplist) > 0: - for ip in iplist: - checkip(ip) - else: +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 2017/8/15 19:43 +# @Author : jiayanhua +# @Site : +# @File : checkdns.py +# @Software: PyCharm Community Edition +#定义域名, +#解析域名获取ip,多个ip访问list中 +#对ip进行http检测 +import dns.resolver +import httplib +import os + +iplist = [] +appdomain = "www.qq.com" + +def get_doaminip(domain=""): + try: + ips=dns.resolver.query(domain,'A') + except Exception,e: + print " resolver is error:"+ str(e) + return + for i in ips.response.answer: + for j in i.items: + iplist.append(j.address) + return True +def checkip(ip): + checkurl = ip + ":80" + #print checkurl + getcontent = "" + httplib.socket.setdefaulttimeout(5) + conn = httplib.HTTPConnection(checkurl) + try: + conn.request("GET","/",headers={"Host":appdomain}) #发起url请求 + r = conn.getresponse() + getcontent = r.read(15) + #print getcontent + finally: + if getcontent == "": + print ip +"[ok]" + else: + print ip + "[error]" +if __name__ == "__main__": + #print iplist + if get_doaminip(appdomain) and len(iplist) > 0: + for ip in iplist: + checkip(ip) + else: print "dns reslove is error" \ No newline at end of file diff --git a/content.txt b/content.txt new file mode 100644 index 0000000..530365d --- /dev/null +++ b/content.txt @@ -0,0 +1,764 @@ +HTTP/1.1 200 OK +Date: Tue, 15 Aug 2017 16:43:22 GMT +Content-Type: text/html; charset=utf-8 +Transfer-Encoding: chunked +Connection: Keep-Alive +Vary: Accept-Encoding +Set-Cookie: BAIDUID=F754A1679CFBAFCBDA989B62FFBD44FE:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com +Set-Cookie: BIDUPSID=F754A1679CFBAFCBDA989B62FFBD44FE; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com +Set-Cookie: PSTM=1502815402; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com +Set-Cookie: BDSVRTM=0; path=/ +Set-Cookie: BD_HOME=0; path=/ +Set-Cookie: H_PS_PSSID=1465_21112_18559_17001_22159; path=/; domain=.baidu.com +P3P: CP=" OTI DSP COR IVA OUR IND COM " +Cache-Control: private +Cxy_all: baidu+2f66ed89946988f9adee45606209d721 +Expires: Tue, 15 Aug 2017 16:42:37 GMT +X-Powered-By: HPHP +Server: BWS/1.1 +X-UA-Compatible: IE=Edge,chrome=1 +BDPAGETYPE: 1 +BDQID: 0xe6587ab60004727d +BDUSERID: 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 百度一下,你就知道 + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/copy.pyc b/copy.pyc new file mode 100644 index 0000000..f4f8998 Binary files /dev/null and b/copy.pyc differ diff --git a/debug.py b/debug.py new file mode 100644 index 0000000..48c2ae8 --- /dev/null +++ b/debug.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" +def show(): + print('a') + if 1 == 1: + return [11,22] + print('b') + +ret=show() + +def show_1(arg): + print(arg) +n=[11,22,33,44] +show_1(n) + +def show(*arg):#转换成元组 + print(arg,type(arg)) +show(1) +show(11,22,33) + +def show(**args):#转成字典 + print(args,type(args)) +show(n1=123,uu=234,bb=000) + + +def show(*args,**kwargs):#顺序不能变,两个星在后 + print(args,type(args)) + print(kwargs,type(kwargs)) +ll=[11,22,33] +dir={'n1':88,'alex':'dfs'} +show(*ll,**dir) +#show(11,22,33,n1=88,alex='dfds')#同上, + +#动态参数应用 +s1="{0} is {1}" #占位 +#result=s1.format('alex','sx') +#print(result) +L=['alex','sb'] +result=s1.format(*L) + +print(result) + +s2='{name} is {acter}' +dir={'name':'alex','acter':'sx'} +result2=s2.format(**dir) +print(result2) +""" +# def func(a): +# b = a + 1 +# # return +# # return b +# # return b +# func(99) +# xxx + + + + + diff --git a/django_08day11/.idea/django_08day11.iml b/django_08day11/.idea/django_08day11.iml new file mode 100644 index 0000000..6711606 --- /dev/null +++ b/django_08day11/.idea/django_08day11.iml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/django_08day11/.idea/misc.xml b/django_08day11/.idea/misc.xml new file mode 100644 index 0000000..32b1140 --- /dev/null +++ b/django_08day11/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/django_08day11/.idea/modules.xml b/django_08day11/.idea/modules.xml new file mode 100644 index 0000000..79df6dc --- /dev/null +++ b/django_08day11/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/django_08day11/.idea/workspace.xml b/django_08day11/.idea/workspace.xml new file mode 100644 index 0000000..dddb5c1 --- /dev/null +++ b/django_08day11/.idea/workspace.xml @@ -0,0 +1,385 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + " % (id, arg,) + return mark_safe(result) +''' \ No newline at end of file diff --git a/django_08day11/adminx/tests.py b/django_08day11/adminx/tests.py new file mode 100644 index 0000000..5982e6b --- /dev/null +++ b/django_08day11/adminx/tests.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.test import TestCase + +# Create your tests here. diff --git a/django_08day11/adminx/urls.py b/django_08day11/adminx/urls.py new file mode 100644 index 0000000..97a3930 --- /dev/null +++ b/django_08day11/adminx/urls.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +"""django_08day11 URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.11/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.conf.urls import url, include + 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) +""" +from django.conf.urls import url +from django.contrib import admin +from django.conf.urls import include + +from web.views import index,login,list +urlpatterns = [ + #url(r'^admin/', admin.site.urls), + #url 对应- 函数 + url(r'^index/', index), + url(r'^login/',login), + #url(r'^list/(\d*)',list), + url(r'^list/(?P\d*)/(?P\d*)/$',list),#P,view,django + url(r'^list/(?P\d*)/$', list,{'id':222}), # P,view +] diff --git a/django_08day11/adminx/urls.pyc b/django_08day11/adminx/urls.pyc new file mode 100644 index 0000000..7841218 Binary files /dev/null and b/django_08day11/adminx/urls.pyc differ diff --git a/django_08day11/adminx/views.py b/django_08day11/adminx/views.py new file mode 100644 index 0000000..e784a0b --- /dev/null +++ b/django_08day11/adminx/views.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.shortcuts import render + +# Create your views here. diff --git a/django_08day11/db.sqlite3 b/django_08day11/db.sqlite3 new file mode 100644 index 0000000..b9d314a Binary files /dev/null and b/django_08day11/db.sqlite3 differ diff --git a/django_08day11/django_08day11/__init__.py b/django_08day11/django_08day11/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django_08day11/django_08day11/__init__.pyc b/django_08day11/django_08day11/__init__.pyc new file mode 100644 index 0000000..28cc62a Binary files /dev/null and b/django_08day11/django_08day11/__init__.pyc differ diff --git a/django_08day11/django_08day11/settings.py b/django_08day11/django_08day11/settings.py new file mode 100644 index 0000000..5df240d --- /dev/null +++ b/django_08day11/django_08day11/settings.py @@ -0,0 +1,140 @@ +# -*- coding: utf-8 -*- + +""" +Django settings for django_08day11 project. + +Generated by 'django-admin startproject' using Django 1.11.7. + +For more information on this file, see +https://docs.djangoproject.com/en/1.11/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.11/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'evzzah!a2tl^opplql@$y3r)bu6w01fbiyqt-*&7*8-juny*o)' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True +#print BASE_DIR +#TEMPLATE_DIRS = ( + + #os.path.join(BASE_DIR,'template'),#join拼接,当前程序路径与后面参数 +#) +#print TEMPLATE_DIRS +ALLOWED_HOSTS = [] + + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'web', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + #'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'django_08day11.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [os.path.join(BASE_DIR,'template')], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'django_08day11.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.11/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': 'test', + 'USER': 'root', + 'PASSWORD': '', + 'HOST': 'localhost', + 'PORT': '3306', + 'OPTIONS': { + #"unix_socket": "/data/mysql5.6/mysql.sock", + 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'" , + #'charset': 'utf8mb4', + 'charset': 'utf8', + + }, + } +} + + +# Password validation +# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/1.11/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.11/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/django_08day11/django_08day11/settings.pyc b/django_08day11/django_08day11/settings.pyc new file mode 100644 index 0000000..14b9fc8 Binary files /dev/null and b/django_08day11/django_08day11/settings.pyc differ diff --git a/django_08day11/django_08day11/urls.py b/django_08day11/django_08day11/urls.py new file mode 100644 index 0000000..95466fb --- /dev/null +++ b/django_08day11/django_08day11/urls.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +"""django_08day11 URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.11/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.conf.urls import url, include + 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) +""" +from django.conf.urls import url +from django.contrib import admin +from django.conf.urls import include + +from web.views import index,Login,list +urlpatterns = [ + url(r'^admin/', admin.site.urls), + #url + # url --file + # file -- funcation + #url(r'^web/',include('web.urls')), + url(r'^web/',include('web.urls')), + #url(r'^adminx/',include('adminx.urls')) +] diff --git a/django_08day11/django_08day11/urls.pyc b/django_08day11/django_08day11/urls.pyc new file mode 100644 index 0000000..e74cf37 Binary files /dev/null and b/django_08day11/django_08day11/urls.pyc differ diff --git a/django_08day11/django_08day11/wsgi.py b/django_08day11/django_08day11/wsgi.py new file mode 100644 index 0000000..83dc81f --- /dev/null +++ b/django_08day11/django_08day11/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for django_08day11 project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_08day11.settings") + +application = get_wsgi_application() diff --git a/django_08day11/django_08day11/wsgi.pyc b/django_08day11/django_08day11/wsgi.pyc new file mode 100644 index 0000000..2505e7f Binary files /dev/null and b/django_08day11/django_08day11/wsgi.pyc differ diff --git a/django_08day11/manage.py b/django_08day11/manage.py new file mode 100644 index 0000000..aab9a04 --- /dev/null +++ b/django_08day11/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_08day11.settings") + try: + from django.core.management import execute_from_command_line + except ImportError: + # The above import may fail for some other reason. Ensure that the + # issue is really that Django is missing to avoid masking other + # exceptions on Python 2. + try: + import django + except ImportError: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) + raise + execute_from_command_line(sys.argv) diff --git a/django_08day11/template/assetlist.html b/django_08day11/template/assetlist.html new file mode 100644 index 0000000..b40d395 --- /dev/null +++ b/django_08day11/template/assetlist.html @@ -0,0 +1,26 @@ +{% extends "master/layout.html" %} +{% block content %} +

{{user}}

+ + {% for item in data %} + + + + + + + {% endfor %} +
{{item.id}}{{item.hostname|upper}}{{item.create_date|date:"Y-m-d H:i:s"}}{{item.update_date|date:"Y-m-d H:i:s"}}
+ + {% if user %} +

zhen

+ {% else %} +

jia

+ {% endif %} + + {% ifequal user 'jiayanhua' %} +

jiayanhua

+ {% else %} +

非 jiayanhua

+ {% endifequal %} +{% endblock %} \ No newline at end of file diff --git a/django_08day11/template/assetlist_bak.html b/django_08day11/template/assetlist_bak.html new file mode 100644 index 0000000..3f8960d --- /dev/null +++ b/django_08day11/template/assetlist_bak.html @@ -0,0 +1,32 @@ + + + + + assetlist + + +

{{user}}

+ + {% for item in data %} + + + + + + + {% endfor %} +
{{item.id}}{{item.hostname|upper}}{{item.create_date|date:"Y-m-d H:i:s"}}{{item.update_date|date:"Y-m-d H:i:s"}}
+ + {% if user %} +

zhen

+ {% else %} +

jia

+ {% endif %} + + {% ifequal user 'jiayanhua' %} +

jiayanhua

+ {% else %} +

非 jiayanhua

+ {% endifequal %} + + \ No newline at end of file diff --git a/django_08day11/template/login.html b/django_08day11/template/login.html new file mode 100644 index 0000000..8ef9a11 --- /dev/null +++ b/django_08day11/template/login.html @@ -0,0 +1,17 @@ + + + + + Title + + +
+ username: +
+ password: + +
+ {{ status }} +
+ + \ No newline at end of file diff --git a/django_08day11/template/master/layout.html b/django_08day11/template/master/layout.html new file mode 100644 index 0000000..05c9020 --- /dev/null +++ b/django_08day11/template/master/layout.html @@ -0,0 +1,14 @@ + + + + + assetlist + + +
公用头部
+
+ {% block content %}{% endblock %} +
+
公用底部
+ + \ No newline at end of file diff --git a/django_08day11/template/register.html b/django_08day11/template/register.html new file mode 100644 index 0000000..928f7d3 --- /dev/null +++ b/django_08day11/template/register.html @@ -0,0 +1,19 @@ + + + + + register + + +
+ + {{form.as_table}} + {{ status }} +
+ + \ No newline at end of file diff --git a/django_08day11/web/__init__.py b/django_08day11/web/__init__.py new file mode 100644 index 0000000..ad68046 --- /dev/null +++ b/django_08day11/web/__init__.py @@ -0,0 +1 @@ +#abc \ No newline at end of file diff --git a/django_08day11/web/__init__.pyc b/django_08day11/web/__init__.pyc new file mode 100644 index 0000000..0c36709 Binary files /dev/null and b/django_08day11/web/__init__.pyc differ diff --git a/django_08day11/web/admin.py b/django_08day11/web/admin.py new file mode 100644 index 0000000..13be29d --- /dev/null +++ b/django_08day11/web/admin.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.contrib import admin + +# Register your models here. diff --git a/django_08day11/web/admin.pyc b/django_08day11/web/admin.pyc new file mode 100644 index 0000000..81663a9 Binary files /dev/null and b/django_08day11/web/admin.pyc differ diff --git a/django_08day11/web/apps.py b/django_08day11/web/apps.py new file mode 100644 index 0000000..a5b84e2 --- /dev/null +++ b/django_08day11/web/apps.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class WebConfig(AppConfig): + name = 'web' diff --git a/django_08day11/web/forms.py b/django_08day11/web/forms.py new file mode 100644 index 0000000..06f8998 --- /dev/null +++ b/django_08day11/web/forms.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 2017/11/29 12:39 +# @Author : jiayanhua +# @Site : +# @File : forms.py +# @Software: PyCharm Community Edition +from django import forms + +class RegisterForm(forms.Form): + username = forms.CharField() + email = forms.EmailField(required=True,error_messages={'invaild':'格式错误'}) + #ip = forms.GenericIPAddressField() diff --git a/django_08day11/web/forms.pyc b/django_08day11/web/forms.pyc new file mode 100644 index 0000000..7f75e6f Binary files /dev/null and b/django_08day11/web/forms.pyc differ diff --git a/django_08day11/web/migrations/0001_initial.py b/django_08day11/web/migrations/0001_initial.py new file mode 100644 index 0000000..88c44a4 --- /dev/null +++ b/django_08day11/web/migrations/0001_initial.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.4 on 2017-11-19 08:01 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='UserInfo', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('username', models.CharField(max_length=50)), + ('password', models.CharField(max_length=50)), + ('Gender', models.BooleanField(default=False)), + ('Age', models.IntegerField(default=19)), + ('memo', models.TextField(default='xxx')), + ('Createdate', models.DateTimeField(default='2017-11-19 15:32:00')), + ('address', models.CharField(max_length=100)), + ], + ), + ] diff --git a/django_08day11/web/migrations/0001_initial.pyc b/django_08day11/web/migrations/0001_initial.pyc new file mode 100644 index 0000000..68b5ede Binary files /dev/null and b/django_08day11/web/migrations/0001_initial.pyc differ diff --git a/django_08day11/web/migrations/0002_auto_20171124_1329.py b/django_08day11/web/migrations/0002_auto_20171124_1329.py new file mode 100644 index 0000000..13f5509 --- /dev/null +++ b/django_08day11/web/migrations/0002_auto_20171124_1329.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.7 on 2017-11-24 05:29 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('web', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Asset', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('hostname', models.CharField(max_length=30)), + ('create_date', models.DateTimeField(auto_now_add=True)), + ('update_date', models.DateTimeField(auto_now=True)), + ], + ), + migrations.CreateModel( + name='Group', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('Name', models.CharField(max_length=50)), + ], + ), + migrations.CreateModel( + name='Temp', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('usertype2', models.CharField(choices=[('1', '\u666e\u901a\u7528\u6237'), ('2', '\u7ba1\u7406\u7528\u6237'), ('3', '\u8d85\u7ea7\u7ba1\u7406\u5458')], max_length=20)), + ], + ), + migrations.CreateModel( + name='User', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('Name', models.CharField(max_length=50)), + ('Email', models.CharField(max_length=100)), + ('group_relation', models.ManyToManyField(to='web.Group')), + ], + ), + migrations.CreateModel( + name='usertype', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=20)), + ], + ), + migrations.RemoveField( + model_name='userinfo', + name='Createdate', + ), + migrations.RemoveField( + model_name='userinfo', + name='address', + ), + migrations.AddField( + model_name='userinfo', + name='CreateDate', + field=models.DateTimeField(default='20171118'), + ), + migrations.AlterField( + model_name='userinfo', + name='Age', + field=models.IntegerField(default='18'), + ), + ] diff --git a/django_08day11/web/migrations/0002_auto_20171124_1329.pyc b/django_08day11/web/migrations/0002_auto_20171124_1329.pyc new file mode 100644 index 0000000..a3293e0 Binary files /dev/null and b/django_08day11/web/migrations/0002_auto_20171124_1329.pyc differ diff --git a/django_08day11/web/migrations/0003_auto_20171124_1331.py b/django_08day11/web/migrations/0003_auto_20171124_1331.py new file mode 100644 index 0000000..9f154d1 --- /dev/null +++ b/django_08day11/web/migrations/0003_auto_20171124_1331.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.7 on 2017-11-24 05:31 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('web', '0002_auto_20171124_1329'), + ] + + operations = [ + migrations.AlterField( + model_name='userinfo', + name='CreateDate', + field=models.DateTimeField(default='2017-11-18 00:22:22'), + ), + ] diff --git a/django_08day11/web/migrations/0003_auto_20171124_1331.pyc b/django_08day11/web/migrations/0003_auto_20171124_1331.pyc new file mode 100644 index 0000000..fb3d0ba Binary files /dev/null and b/django_08day11/web/migrations/0003_auto_20171124_1331.pyc differ diff --git a/django_08day11/web/migrations/0004_test.py b/django_08day11/web/migrations/0004_test.py new file mode 100644 index 0000000..787564a --- /dev/null +++ b/django_08day11/web/migrations/0004_test.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.7 on 2017-11-24 06:08 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('web', '0003_auto_20171124_1331'), + ] + + operations = [ + migrations.CreateModel( + name='Test', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=30)), + ('Age', models.IntegerField(default=23)), + ], + ), + ] diff --git a/django_08day11/web/migrations/0004_test.pyc b/django_08day11/web/migrations/0004_test.pyc new file mode 100644 index 0000000..8cb6320 Binary files /dev/null and b/django_08day11/web/migrations/0004_test.pyc differ diff --git a/django_08day11/web/migrations/__init__.py b/django_08day11/web/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django_08day11/web/migrations/__init__.pyc b/django_08day11/web/migrations/__init__.pyc new file mode 100644 index 0000000..3c5e1a2 Binary files /dev/null and b/django_08day11/web/migrations/__init__.pyc differ diff --git a/django_08day11/web/models.py b/django_08day11/web/models.py new file mode 100644 index 0000000..0273625 --- /dev/null +++ b/django_08day11/web/models.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models + +# Create your models here. +class usertype(models.Model): + name = models.CharField(max_length=20) + def __str__(self): + return self.name +class UserInfo(models.Model): + username = models.CharField(max_length=50) + password = models.CharField(max_length=50) + Gender = models.BooleanField(default=False) + Age = models.IntegerField(default=20) + memo = models.TextField(default='xxx') + Createdate = models.DateTimeField(default='2017-11-19 15:32:00') + address = models.CharField(max_length=100) + #type = models.IntegerField(max_length=10) + type = models.ForeignKey('usertype') + def __str__(self): + return self.name + +#many to many +class Group(models.Model): + Name = models.CharField(max_length=50) + def __str__(self): + return self.name + +class User(models.Model): + Name = models.CharField(max_length=50) + Email = models.CharField(max_length=100) + group_relation = models.ManyToManyField('Group') + #会自动生成第三张表 + def __str__(self): + return self.name + +class Asset(models.Model): #不用关系创建时间和修改时间 + hostname = models.CharField(max_length=30) + create_date = models.DateTimeField(auto_now_add=True) + update_date = models.DateTimeField(auto_now=True) + +class Temp(models.Model): + GENDER_CHOICE = { + (u'1',u'普通用户'), + (u'2',u'管理用户'), + (u'3',u'超级管理员') + } + usertype2 = models.CharField(max_length=20,choices = GENDER_CHOICE) + +class UserInfo(models.Model): + username = models.CharField(max_length=50) + password = models.CharField(max_length=50) + Gender = models.BooleanField(default=False)#性别,布尔型 + Age = models.IntegerField(default='18') #整型 + memo = models.TextField(default='xxx') # 文本 + CreateDate = models.DateTimeField(default='2017-11-18 00:22:22') +class Test(models.Model): + name = models.CharField(max_length=30) + Age = models.IntegerField(default=23) \ No newline at end of file diff --git a/django_08day11/web/models.pyc b/django_08day11/web/models.pyc new file mode 100644 index 0000000..b0c0f53 Binary files /dev/null and b/django_08day11/web/models.pyc differ diff --git a/django_08day11/web/tests.py b/django_08day11/web/tests.py new file mode 100644 index 0000000..5982e6b --- /dev/null +++ b/django_08day11/web/tests.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.test import TestCase + +# Create your tests here. diff --git a/django_08day11/web/urls.py b/django_08day11/web/urls.py new file mode 100644 index 0000000..3d360e2 --- /dev/null +++ b/django_08day11/web/urls.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- + +"""django_08day11 URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.11/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.conf.urls import url, include + 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) +""" +from django.conf.urls import url +from django.contrib import admin +from web.views import index,Login,list,Add,Delete,Update,Get,AssetList,Register +urlpatterns = [ + #url(r'^admin/', admin.site.urls), + #url 对应- 函数 + url(r'^index/', index), + url(r'^login/',Login), + #url(r'^list/(\d*)',list), + url(r'^list/(?P\d*)/(?P\d*)/$',list),#P,view,django + url(r'^list/(?P\d*)/$', list,{'id':222}), # P,view + url(r'^add/(?P\w*)/$',Add),#\d*表示数字 + url(r'^delete/(?P\d*)/$',Delete), + url(r'^update/(?P\d*)/(?P\w*)/$',Update), + url(r'^get/(?P\w*)/$',Get), + url(r'^assetlist/$',AssetList), + url(r'^register/$',Register), +] diff --git a/django_08day11/web/urls.pyc b/django_08day11/web/urls.pyc new file mode 100644 index 0000000..6984bda Binary files /dev/null and b/django_08day11/web/urls.pyc differ diff --git a/django_08day11/web/views.py b/django_08day11/web/views.py new file mode 100644 index 0000000..ad1db5e --- /dev/null +++ b/django_08day11/web/views.py @@ -0,0 +1,109 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.shortcuts import render +from django.http.response import HttpResponse +from web.models import Asset,UserInfo +from django.shortcuts import render_to_response +from web.forms import RegisterForm +#from django.db.models.manager.Manager import * + +# Create your views here. +def Register(request): + registerForm = RegisterForm() + if request.method == 'POST':#如果post提交数据 + form = RegisterForm(request.POST) #将获取数据赋值给form + if form.is_valid():#验证有效性 + data = form.cleaned_data + #data2 = form. + print data + else:#如果无效,返回form错误方法 + #print form.errors.as_json() + #print type(form.errors) + #django.forms.utils.ErrorDict + temp = form.errors.as_data() + print temp['email'][0].messages[0] + #django.core.exceptions.ValidationError temp['email'][0] + #print type(temp['email'][0]) + #print temp.['email'][0]['message'] + #else:#如果普通访问,返回注册页面 + return render_to_response('register.html', {'form':registerForm}) +''' + if request.method == "POST": #跨站请求宝403 + user = request.POST.get('username',None) + pwd = request.POST.get('password',None) + #print user,pwd + result = UserInfo.objects.filter(username=user,password=pwd).count() + if result == 1: + return HttpResponse("login sucess") + else: + return render_to_response('login.html',{'status':'用户名密码错误'}) + else: + return render_to_response('login.html') +''' +def Login(request): + if request.method == "POST": #跨站请求宝403 + user = request.POST.get('username',None) + pwd = request.POST.get('password',None) + #print user,pwd + result = UserInfo.objects.filter(username=user,password=pwd).count() + if result == 1: + return HttpResponse("login sucess") + else: + return render_to_response('login.html',{'status':'用户名密码错误'}) + else: + return render_to_response('login.html') + +def index(request):#django 固定格式,接受http请求 + return HttpResponse('index') #同上固定格式,返回http + + +def list(request,name,id):#传递参数与urls模板一致,多个需要按顺序 + print name,id + return HttpResponse('list') + +def Add(request,name):#添加传入name作为hostname + Asset.objects.create(hostname=name) #xx.objects django默认类的实例,提供了get、put等方法 + #print type(Asset.objects) #打印引用方法出处 + #django.db.models.manager.Manager #对数据库的增删改查 + return HttpResponse('ok') + +def Delete(request,id):#删除时,传入id即可 + Asset.objects.get(id=id).delete() + return HttpResponse('ok') + +def Update(request,id,hostname): #更新数据库 + #更新单条数据 + ''' + obj = Asset.objects.get(id=id) #get只能获取一条数据,只要获取不到就报错 + obj.hostname = hostname + obj.save() + ''' + Asset.objects.filter(id__gt=id),update(hostname=hostname) #批量修改大于指定id的hostnme全部修改 + return HttpResponse('ok') + +def Get(request,hostname): + assetlist = Asset.objects.filter(hostname__contains=hostname) #fileter 获取多条数据,没有数据不会报错。而且与get获取的类型不一样,get获取到一个对象,filter获取多个对象的集合 + #for item in assetlist:#循环列出id + # print item.id + #print assetlist + + #alldata = Asset.objects.all() #所有数据 + #print alldata.query #SELECT `web_asset`.`id`, `web_asset`.`hostname`, `web_asset`.`create_date`, `web_asset`.`update_date` FROM `web_asset` + + alldata = Asset.objects.all().values('id','hostname') #映射字段,返回指定字段 + print alldata + print alldata.query + + + '''' + temp = Asset.objects.all()[0:2] #所有数据的0-2,分页需要 + alldata = Asset.objects.all().order_by('id') #正序 + alldata = Asset.objects.all().order_by('-id') #倒叙 + ''' + return HttpResponse('ok') + +def AssetList(request): + assetlist = Asset.objects.all() + result = render_to_response('assetlist.html',{'data':assetlist,'user':"jiayanhua"}) #将数据嵌入到html + return result \ No newline at end of file diff --git a/django_08day11/web/views.pyc b/django_08day11/web/views.pyc new file mode 100644 index 0000000..b58b5cc Binary files /dev/null and b/django_08day11/web/views.pyc differ diff --git a/djangotest/Model/__init__.py b/djangotest/Model/__init__.py new file mode 100644 index 0000000..353ca62 --- /dev/null +++ b/djangotest/Model/__init__.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 2017/11/12 10:18 +# @Author : jiayanhua +# @Site : +# @File : __init__.py.py +# @Software: PyCharm Community Edition \ No newline at end of file diff --git a/djangotest/Template/Account/login.html b/djangotest/Template/Account/login.html new file mode 100644 index 0000000..5e91c36 --- /dev/null +++ b/djangotest/Template/Account/login.html @@ -0,0 +1,11 @@ + + + + + Title + + +

username:

+

password:

+ + \ No newline at end of file diff --git a/djangotest/Template/__init__.py b/djangotest/Template/__init__.py new file mode 100644 index 0000000..75c2ae6 --- /dev/null +++ b/djangotest/Template/__init__.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 2017/11/12 10:19 +# @Author : jiayanhua +# @Site : +# @File : __init__.py.py +# @Software: PyCharm Community Edition \ No newline at end of file diff --git a/djangotest/View/Account.py b/djangotest/View/Account.py new file mode 100644 index 0000000..2e9e55e --- /dev/null +++ b/djangotest/View/Account.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 2017/11/12 10:28 +# @Author : jiayanhua +# @Site : +# @File : Account.py +# @Software: PyCharm Community Edition +# 处理账号相关的 +def login(): + #读取html文件 + #再与数据库中的账号密码进行比对,对数据库存、取用到model模块 + #返回给用户时用到view + f = file('E:\example\djangotest\Template\Account\login.html') + data = f.read() + return data + #return "login" + +def loginout(): + return "loginout" + +def changepasswd(): + return "changepassdd" + diff --git a/djangotest/View/Account.pyc b/djangotest/View/Account.pyc new file mode 100644 index 0000000..8ef18a6 Binary files /dev/null and b/djangotest/View/Account.pyc differ diff --git a/djangotest/View/Admin.py b/djangotest/View/Admin.py new file mode 100644 index 0000000..49b0d05 --- /dev/null +++ b/djangotest/View/Admin.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 2017/11/12 10:28 +# @Author : jiayanhua +# @Site : +# @File : Admin.py +# @Software: PyCharm Community Edition +#管理后台 +def index(): + return "index" \ No newline at end of file diff --git a/djangotest/View/Admin.pyc b/djangotest/View/Admin.pyc new file mode 100644 index 0000000..11075ff Binary files /dev/null and b/djangotest/View/Admin.pyc differ diff --git a/djangotest/View/__init__.py b/djangotest/View/__init__.py new file mode 100644 index 0000000..93560ad --- /dev/null +++ b/djangotest/View/__init__.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 2017/11/12 10:20 +# @Author : jiayanhua +# @Site : +# @File : __init__.py.py +# @Software: PyCharm Community Edition \ No newline at end of file diff --git a/djangotest/View/__init__.pyc b/djangotest/View/__init__.pyc new file mode 100644 index 0000000..126dedb Binary files /dev/null and b/djangotest/View/__init__.pyc differ diff --git a/djangotest/config.py b/djangotest/config.py new file mode 100644 index 0000000..922ed69 --- /dev/null +++ b/djangotest/config.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 2017/11/9 0:29 +# @Author : jiayanhua +# @Site : +# @File : config.py +# @Software: PyCharm Community Edition + +def login(): + return 'login' +def logout(): + return 'logout' + +url = ( + ('/login/',login), + ('/logout',logout), +) \ No newline at end of file diff --git a/djangotest/index.py b/djangotest/index.py new file mode 100644 index 0000000..bdae813 --- /dev/null +++ b/djangotest/index.py @@ -0,0 +1,52 @@ + +# -*- coding: utf-8 -*- +# @Time : 2017/11/8 23:30 +# @Author : jiayanhua +# @Site : +# @File : wsgi.py +# @Software: PyCharm Community Edition +from wsgiref.simple_server import make_server +from View.Admin import * +from View.Account import * + +''' +def login(): + #file + #htmls + html ='

username:

password:

' + return html +def logout(): + return 'logout' +''' +urls = ( + ('/index/',index), + ('/login/',login), + ('/loginout/',loginout), +) +#框架如下,业务层只需要关心上面的部分 +def RunServer(environ, start_response): + start_response('200 OK', [('Content-Type', 'text/html')]) + url = environ['PATH_INFO'] + func = None #赋值 + for i in urls: + if i[0] == url: + func = i[1] + break #匹配到后终止循环 + if func:#判断正确 + result = func() + else: + return '404' + return result +''' + if url == '/index/': + return "

index

" + elif url == '/loing/': + return "

login

" + else: + return "test" + return '

Hello, web!

' +''' +if __name__ == '__main__': + httpd = make_server('', 8000, RunServer) + print "Serving HTTP on port 8000..." + httpd.serve_forever() \ No newline at end of file diff --git a/djangotest/testsocket.py b/djangotest/testsocket.py new file mode 100644 index 0000000..b694bc8 --- /dev/null +++ b/djangotest/testsocket.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 2017/11/8 23:25 +# @Author : jiayanhua +# @Site : +# @File : socket.py +# @Software: PyCharm Community Edition +import socket + + +def handle_request(client): + buf = client.recv(1024) + client.send("HTTP/1.1 200 OK\r\n\r\n") + client.send("Hello, Seven") + + +def main(): + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.bind(('localhost', 8000)) + sock.listen(5) + + while True: + connection, address = sock.accept() + handle_request(connection) + connection.close() + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/ex40.py b/ex40.py deleted file mode 100644 index 6ac57bc..0000000 --- a/ex40.py +++ /dev/null @@ -1,20 +0,0 @@ -#-*- coding:utf8 -*- -cities={'CA':"San",'MI':'detroit','FL':'Jack'} -cities['NY']='New yourk' -cities['OR']='Portland' - -def find_city(themap,state): - if state in themap: - return themap[state] - else: - return "Not found" - -cities['_find']=find_city - -while True: - print "State?(ENTER to quit)", - state=raw_input("> ") - if not state:break - city_found=cities['_find'](cities,state) - print city_found - diff --git a/ex42.py b/ex42.py deleted file mode 100644 index 0b9a346..0000000 --- a/ex42.py +++ /dev/null @@ -1,26 +0,0 @@ -#!-*- coding:utf8 -*- -class TheThing(object): - """docstring for TheThing""" - def __init__(self): - self.number = 0 - - def some_funcation(self): - print "I got called." - - def add_me_up(self,more): - self.number += more - return self.number - -a=TheThing() -b=TheThing() - -a.some_funcation() -b.some_funcation() - -print a.add_me_up(20) -print a.add_me_up(20) -print b.add_me_up(20) -print b.add_me_up(20) - -print a.number -print b.number diff --git a/list_vm.py b/list_vm.py index 9c073b5..2b560d0 100644 --- a/list_vm.py +++ b/list_vm.py @@ -1,98 +1,98 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -#auth :jyh -import sys -try: - import libvirt - HAS_LIBVIRT=True -except Exception: - HAS_LIBVIRT=False -def is_virtual(): - """ - 判断当前系统是不是支持虚拟化 - """ - if not HAS_LIBVIRT: - sys.exit("current system not support virt") - return 'virt' -def get_conn(): - ''' - 获取libvirt连接句柄,用户提供libvirt接口 - ''' - if is_virtual() == 'virt': - try: - conn=libvirt.open('qeum:///system') - except Exception as e: - sys.exit(e) - return conn - -def close_conn(conn): - ''' - 关闭conn 连接 - :param conn: - :return: - ''' - return conn.close() -def list_active_vms(): - ''' - 列出所有 - :return: - ''' - vms_list=[] - conn=get_conn() - doamin_list=conn.listDoaminsID() - for id in doamin_list: - vms_list.append(conn.lookupByID(id).name()) - close_conn(conn) - return vms_list -def list_inactive_vms(): - ''' - 列出关闭的机器 - :return: - ''' - vms_list=[] - conn=get_conn() - for id in conn.listDefinedDomains(): - vms_list.append(id) - close_conn(conn) - return vms_list -def list_all_vms(): - ''' - - :return: - ''' - vms=[] - vms.extend(list_active_vms()) - vms.extend(list_inactive_vms()) - return vms -def get_capability(): - ''' - - :return: - ''' - conn=get_conn() - capability=conn.getCapabilities() - conn.close() - return capability -def get_hostname: - ''' - - :return: - ''' - conn=get_conn() - hostname=conn.getHostname() - conn.close() - return hostname -def get_max_vcpus(): - ''' - - :return: - ''' - conn=get_conn() - max_vcpus=conn.getMaxVcpus(None) - conn.close() - return max_vcpus -if __name__ == "__main__": - print "当前主机%s的虚拟机列表:"%(get_hostname()) - for vms in list_active_vms(): - print vms - +#!/usr/bin/env python +# -*- coding: utf-8 -*- +#auth :jyh +import sys +try: + import libvirt + HAS_LIBVIRT=True +except Exception: + HAS_LIBVIRT=False +def is_virtual(): + """ + 判断当前系统是不是支持虚拟化 + """ + if not HAS_LIBVIRT: + sys.exit("current system not support virt") + return 'virt' +def get_conn(): + ''' + 获取libvirt连接句柄,用户提供libvirt接口 + ''' + if is_virtual() == 'virt': + try: + conn=libvirt.open('qeum:///system') + except Exception as e: + sys.exit(e) + return conn + +def close_conn(conn): + ''' + 关闭conn 连接 + :param conn: + :return: + ''' + return conn.close() +def list_active_vms(): + ''' + 列出所有 + :return: + ''' + vms_list=[] + conn=get_conn() + doamin_list=conn.listDoaminsID() + for id in doamin_list: + vms_list.append(conn.lookupByID(id).name()) + close_conn(conn) + return vms_list +def list_inactive_vms(): + ''' + 列出关闭的机器 + :return: + ''' + vms_list=[] + conn=get_conn() + for id in conn.listDefinedDomains(): + vms_list.append(id) + close_conn(conn) + return vms_list +def list_all_vms(): + ''' + + :return: + ''' + vms=[] + vms.extend(list_active_vms()) + vms.extend(list_inactive_vms()) + return vms +def get_capability(): + ''' + + :return: + ''' + conn=get_conn() + capability=conn.getCapabilities() + conn.close() + return capability +def get_hostname: + ''' + + :return: + ''' + conn=get_conn() + hostname=conn.getHostname() + conn.close() + return hostname +def get_max_vcpus(): + ''' + + :return: + ''' + conn=get_conn() + max_vcpus=conn.getMaxVcpus(None) + conn.close() + return max_vcpus +if __name__ == "__main__": + print "当前主机%s的虚拟机列表:"%(get_hostname()) + for vms in list_active_vms(): + print vms + diff --git a/psutil.py b/psutil.py new file mode 100644 index 0000000..e69de29 diff --git a/recive.py b/recive.py new file mode 100644 index 0000000..42d0f32 --- /dev/null +++ b/recive.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 2017/9/15 21:37 +# @Author : jiayanhua +# @Site : +# @File : recive.py +# @Software: PyCharm Community Edition + +# !/usr/bin/env python +import pika + +connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost')) +channel = connection.channel() + +channel.queue_declare(queue='hello') + +print ' [*] Waiting for messages. To exit press CTRL+C' + + +def callback(ch, method, properties, body): + print " [x] Received %r" % (body,) + + +channel.basic_consume(callback, + queue='hello', + no_ack=True) + +channel.start_consuming() \ No newline at end of file diff --git a/sbx.xls b/sbx.xls new file mode 100644 index 0000000..951e0ef Binary files /dev/null and b/sbx.xls differ diff --git a/send.py b/send.py new file mode 100644 index 0000000..da5f051 --- /dev/null +++ b/send.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 2017/9/15 21:36 +# @Author : jiayanhua +# @Site : +# @File : send.py +# @Software: PyCharm Community Edition + +import pika + +connection = pika.BlockingConnection(pika.ConnectionParameters( + host='localhost')) +channel = connection.channel() + +channel.queue_declare(queue='hello') + +channel.basic_publish(exchange='', + routing_key='hello', + body='Hello World!') +print " [x] Sent 'Hello World!'" +connection.close() \ No newline at end of file diff --git a/site_count.py b/site_count.py index 2414294..b15203a 100644 --- a/site_count.py +++ b/site_count.py @@ -1,81 +1,81 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# @Time : 2017/8/12 19:19 -# @Author : jiayanhua -# @Site : -# @File : site_count.py -# @Software: PyCharm Community Edition -#xlswriter -''' -1、准备 -创建一个Excel文件;创建一个工作表;创建一个图标对象;定义表头,表列;准备7天数据 -2、定义格式 -设置整个工作表格式,边框像素加1; -定义title格式对象,边框加粗,像素1,底色#cccccc; -tiltle 居中,内容加粗 -定义avg边框加粗1,数字格式小数点 -3、插入数据 -4、定义函数 -5、设置图标宽、高、大标题,y轴小标题 -''' - -import xlsxwriter - -workbook = xlsxwriter.Workbook('site_count.xlsx') #create excel file object -worksheet = workbook.add_worksheet() #create sheet object -chart = workbook.add_chart({'type':'column'}) #create chart object -#title -title = [u'业务名称',u'星期一',u'星期二',u'星期三',u'星期四',u'星期五',u'星期六',u'星期日',u'平均流量'] -#列 -buname = [u'业务官网',u'新闻中心',u'购物频道',u'体育频道',u'亲子频道'] -#数据 -data = [[100,150,120,130,111,100,105],[100,150,120,130,111,100,105],[100,150,120,130,111,100,105],[100,150,120,130,111,100,105],[100,150,120,130,111,100,105]] -#定义格式 -format = workbook.add_format() #create fomart object -format.set_border(1) #边框加粗 # - -format_title = workbook.add_format() -format_title.set_border(1)#边框加粗,像素1 -format_title.set_bg_color('#cccccc')#背景色 -format_title.set_align('center') #居中 -format_title.set_bold()#字体加粗 - -format_avg = workbook.add_format() -format_avg.set_border(1) -format_avg.set_num_format('0.00') #设置浮点位 -#插入数据 -worksheet.write_row('A1',title,format_title) -worksheet.write_column('A2',buname,format) -worksheet.write_row('B2',data[0],format) -worksheet.write_row('B3',data[1],format) -worksheet.write_row('B4',data[2],format) -worksheet.write_row('B5',data[3],format) -worksheet.write_row('B6',data[4],format) -#定义 -def chart_series(cur_now): - worksheet.write_formula('I'+cur_now,'=AVERAGE(B'+cur_now+':H'+cur_now+')',format_avg) -#添加一个数据系列到图标 - chart.add_series({ - 'categories':'=Sheet1!$B$1:$H$1', #设置图标标签范围 - 'values':'=Sheet1!$B$'+cur_now+':$H$'+cur_now, #设置图标数据范围 - 'line':{'color':'black'},#设置图标线条属性 - 'name':'=Sheet1!$A$'+cur_now, - }) - -for row in range(2,7): - chart_series(str(row)) - -#chart.set_table() -#chart.set_style(30) -chart.set_size({'width':577,'height':287}) -chart.set_title({'name':u'业务流量报表'}) -chart.set_y_axis({'name':'Mb/s'}) - -worksheet.insert_chart('A8',chart) -workbook.close() - - - - - - +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 2017/8/12 19:19 +# @Author : jiayanhua +# @Site : +# @File : site_count.py +# @Software: PyCharm Community Edition +#xlswriter +''' +1、准备 +创建一个Excel文件;创建一个工作表;创建一个图标对象;定义表头,表列;准备7天数据 +2、定义格式 +设置整个工作表格式,边框像素加1; +定义title格式对象,边框加粗,像素1,底色#cccccc; +tiltle 居中,内容加粗 +定义avg边框加粗1,数字格式小数点 +3、插入数据 +4、定义函数 +5、设置图标宽、高、大标题,y轴小标题 +''' + +import xlsxwriter + +workbook = xlsxwriter.Workbook('site_count.xlsx') #create excel file object +worksheet = workbook.add_worksheet() #create sheet object +chart = workbook.add_chart({'type':'column'}) #create chart object +#title +title = [u'业务名称',u'星期一',u'星期二',u'星期三',u'星期四',u'星期五',u'星期六',u'星期日',u'平均流量'] +#列 +buname = [u'业务官网',u'新闻中心',u'购物频道',u'体育频道',u'亲子频道'] +#数据 +data = [[100,150,120,130,111,100,105],[100,150,120,130,111,100,105],[100,150,120,130,111,100,105],[100,150,120,130,111,100,105],[100,150,120,130,111,100,105]] +#定义格式 +format = workbook.add_format() #create fomart object +format.set_border(1) #边框加粗 # + +format_title = workbook.add_format() +format_title.set_border(1)#边框加粗,像素1 +format_title.set_bg_color('#cccccc')#背景色 +format_title.set_align('center') #居中 +format_title.set_bold()#字体加粗 + +format_avg = workbook.add_format() +format_avg.set_border(1) +format_avg.set_num_format('0.00') #设置浮点位 +#插入数据 +worksheet.write_row('A1',title,format_title) +worksheet.write_column('A2',buname,format) +worksheet.write_row('B2',data[0],format) +worksheet.write_row('B3',data[1],format) +worksheet.write_row('B4',data[2],format) +worksheet.write_row('B5',data[3],format) +worksheet.write_row('B6',data[4],format) +#定义 +def chart_series(cur_now): + worksheet.write_formula('I'+cur_now,'=AVERAGE(B'+cur_now+':H'+cur_now+')',format_avg) +#添加一个数据系列到图标 + chart.add_series({ + 'categories':'=Sheet1!$B$1:$H$1', #设置图标标签范围 + 'values':'=Sheet1!$B$'+cur_now+':$H$'+cur_now, #设置图标数据范围 + 'line':{'color':'black'},#设置图标线条属性 + 'name':'=Sheet1!$A$'+cur_now, + }) + +for row in range(2,7): + chart_series(str(row)) + +#chart.set_table() +#chart.set_style(30) +chart.set_size({'width':577,'height':287}) +chart.set_title({'name':u'业务流量报表'}) +chart.set_y_axis({'name':'Mb/s'}) + +worksheet.insert_chart('A8',chart) +workbook.close() + + + + + + diff --git a/testbook.xlsx b/testbook.xlsx new file mode 100644 index 0000000..dd61a05 Binary files /dev/null and b/testbook.xlsx differ diff --git a/weburlcheck.py b/weburlcheck.py index beb884b..adc2723 100644 --- a/weburlcheck.py +++ b/weburlcheck.py @@ -1,67 +1,67 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# @Time : 2017/8/15 21:36 -# @Author : jiayanhua -# @Site : -# @File : weburlcheck.py -# @Software: PyCharm Community Edition - -import os -import sys -import time -import pycurl - - -URL = "http://www.baidu.com" # -c = pycurl.Curl() #创建url对象 -c.setopt(pycurl.URL,URL) #定义请求URL常量 -c.setopt(pycurl.CONNECTTIMEOUT,5) #定义http请求等待时间 -c.setopt(pycurl.TIMEOUT,5) #请求超时时间 -c.setopt(pycurl.NOPROGRESS,1) #屏蔽下载进度条 -c.setopt(pycurl.FORBID_REUSE,1) #完成交互后强制断开 -c.setopt(pycurl.MAXREDIRS,1) # 重定向最大1 -c.setopt(pycurl.DNS_CACHE_TIMEOUT,30) #dns缓存信息的时间为30 -#wb格式打开文件,存储http头部及内容信息 -indexfile = open(os.path.dirname(os.path.realpath(__file__)) + "/content.txt",'wb') - -c.setopt(pycurl.WRITEHEADER,indexfile) #http header 写入文件 -c.setopt(pycurl.WRITEDATA,indexfile) #http 内容写入文件 - -try: - c.perform() #提交请求 -except Exception,e: - print "connect is error " + str(e) - indexfile.close() - c.close() - sys.exit() - -NAMELOOKUP_TIME = c.getinfo(c.NAMELOOKUP_TIME) -CONNECT_TIME = c.getinfo(c.CONNECT_TIME) -PRETRANSFER_TIME = c.getinfo(c.PRETRANSFER_TIME) -STARTTRANSFER_TIME = c.getinfo(c.STARTTRANSFER_TIME) -TOTAL_TIME = c.getinfo(c.TOTAL_TIME) -HTTP_CODE = c.getinfo(c.HTTP_CODE) -SIZE_DOWNLOAD = c.getinfo(c.SIZE_DOWNLOAD) -HEADER_SIZE = c.getinfo(c.HEADER_SIZE) -SPEED_DOWNLOAD = c.getinfo(c.SPEED_DOWNLOAD) - -#print all -print "HTTP状态码: %s" %(HTTP_CODE) -print "DNS解析时间: %.2f ms" %(NAMELOOKUP_TIME * 1000) -print "建立连接时间: %.2f ms" %(CONNECT_TIME * 1000) -print "准备传输时间: %.2f ms" %(PRETRANSFER_TIME * 1000) -print "开始传输时间: %.2f ms" %(STARTTRANSFER_TIME * 1000) -print "传输结束总时间: %.2f ms" %(TOTAL_TIME * 1000) -print "下载包数据大小: %d bytes/s" %(SIZE_DOWNLOAD) -print "HTTPhead 大小: %d bytes/s" %(HEADER_SIZE) -print "平均下载速度: %d bytes/s" %(SPEED_DOWNLOAD) - -#关闭文件 -indexfile.close() -c.close() - - - - - - +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 2017/8/15 21:36 +# @Author : jiayanhua +# @Site : +# @File : weburlcheck.py +# @Software: PyCharm Community Edition + +import os +import sys +import time +import pycurl + + +URL = "http://www.baidu.com" # +c = pycurl.Curl() #创建url对象 +c.setopt(pycurl.URL,URL) #定义请求URL常量 +c.setopt(pycurl.CONNECTTIMEOUT,5) #定义http请求等待时间 +c.setopt(pycurl.TIMEOUT,5) #请求超时时间 +c.setopt(pycurl.NOPROGRESS,1) #屏蔽下载进度条 +c.setopt(pycurl.FORBID_REUSE,1) #完成交互后强制断开 +c.setopt(pycurl.MAXREDIRS,1) # 重定向最大1 +c.setopt(pycurl.DNS_CACHE_TIMEOUT,30) #dns缓存信息的时间为30 +#wb格式打开文件,存储http头部及内容信息 +indexfile = open(os.path.dirname(os.path.realpath(__file__)) + "/content.txt",'wb') + +c.setopt(pycurl.WRITEHEADER,indexfile) #http header 写入文件 +c.setopt(pycurl.WRITEDATA,indexfile) #http 内容写入文件 + +try: + c.perform() #提交请求 +except Exception,e: + print "connect is error " + str(e) + indexfile.close() + c.close() + sys.exit() + +NAMELOOKUP_TIME = c.getinfo(c.NAMELOOKUP_TIME) +CONNECT_TIME = c.getinfo(c.CONNECT_TIME) +PRETRANSFER_TIME = c.getinfo(c.PRETRANSFER_TIME) +STARTTRANSFER_TIME = c.getinfo(c.STARTTRANSFER_TIME) +TOTAL_TIME = c.getinfo(c.TOTAL_TIME) +HTTP_CODE = c.getinfo(c.HTTP_CODE) +SIZE_DOWNLOAD = c.getinfo(c.SIZE_DOWNLOAD) +HEADER_SIZE = c.getinfo(c.HEADER_SIZE) +SPEED_DOWNLOAD = c.getinfo(c.SPEED_DOWNLOAD) + +#print all +print "HTTP状态码: %s" %(HTTP_CODE) +print "DNS解析时间: %.2f ms" %(NAMELOOKUP_TIME * 1000) +print "建立连接时间: %.2f ms" %(CONNECT_TIME * 1000) +print "准备传输时间: %.2f ms" %(PRETRANSFER_TIME * 1000) +print "开始传输时间: %.2f ms" %(STARTTRANSFER_TIME * 1000) +print "传输结束总时间: %.2f ms" %(TOTAL_TIME * 1000) +print "下载包数据大小: %d bytes/s" %(SIZE_DOWNLOAD) +print "HTTPhead 大小: %d bytes/s" %(HEADER_SIZE) +print "平均下载速度: %d bytes/s" %(SPEED_DOWNLOAD) + +#关闭文件 +indexfile.close() +c.close() + + + + + + diff --git a/xls.py b/xls.py new file mode 100644 index 0000000..9fdfbdc --- /dev/null +++ b/xls.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @Time : 2017/8/12 9:36 +# @Author : jiayanhua +# @Site : +# @File : xls.py +# @Software: PyCharm Community Edition +import xlsxwriter + +workbook = xlsxwriter.Workbook('xls.xlsx') +worksheet = workbook.add_worksheet() + +worksheet.set_column('A:A',20) +bold=workbook.add_format({'bold':True}) + +worksheet.write('A1','Hello word') +worksheet.write('A2','taiyan',bold) + +worksheet.write(2,0,32) +worksheet.write(3,0,23.5) +worksheet.write(4,0,'=SUM(A3:A4)') + +workbook.close() + + diff --git a/xls.xlsx b/xls.xlsx new file mode 100644 index 0000000..ba1049a Binary files /dev/null and b/xls.xlsx differ diff --git a/xxx.xlsx b/xxx.xlsx new file mode 100644 index 0000000..b42fea6 Binary files /dev/null and b/xxx.xlsx differ