Skip to content

Commit

Permalink
Merge pull request #30 from liangliangyy/weixin
Browse files Browse the repository at this point in the history
增加微信功能
  • Loading branch information
liangliangyy committed Sep 3, 2017
2 parents 86d2318 + 9ba3393 commit 09f3e50
Show file tree
Hide file tree
Showing 20 changed files with 528 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ google93fd32dbd906620a.html
baidu_verify_FlHL7cUyC9.html
BingSiteAuth.xml
cb9339dbe2ff86a5aa169d28dba5f615.txt
werobot_session

1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist: precise
language: python
python:
- "3.4"
Expand Down
4 changes: 3 additions & 1 deletion DjangoBlog/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
'accounts',
'comments',
'oauth',
'servermanager',
'compressor'
]

Expand Down Expand Up @@ -234,7 +235,8 @@
SERVER_EMAIL = os.environ.get('DJANGO_EMAIL_USER')
# 设置debug=false 未处理异常邮件通知
ADMINS = [('liangliang', 'liangliangyy@gmail.com')]

# 微信管理员密码(两次md5获得)
WXADMIN = '995F03AC401D6CABABAEF756FC4D43C7'
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
Expand Down
2 changes: 1 addition & 1 deletion DjangoBlog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps},
name='django.contrib.sitemaps.views.sitemap'),
url(r'^feed/$', DjangoBlogFeed()),

url(r'^search', include('haystack.urls'), name='search'),
url(r'', include('servermanager.urls', namespace='servermanager', app_name='servermanagers'))
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
9 changes: 6 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ appdirs==1.4.3
Django==1.11.4
django-appconf==1.0.2
django-autoslug==1.9.3
django-compressor==2.1.1
django-compressor==2.2
django-debug-toolbar==1.8
django-haystack==2.6.1
django-ipware==1.1.6
django-pagedown==0.1.3
django-uuslug==1.1.8
jieba==0.38
jieba==0.39
jsonpickle==0.9.5
markdown2==2.3.4
mistune==0.7.4
olefile==0.44
Expand All @@ -21,10 +22,12 @@ python-memcached==1.58
python-slugify==1.2.4
pytz==2017.2
rcssmin==1.0.6
requests==2.18.3
requests==2.18.4
rjsmin==1.0.12
six==1.10.0
sqlparse==0.2.3
Unidecode==0.4.21
urllib3==1.22
webencodings==0.5.1
WeRoBot==1.1.1
Whoosh==2.7.4
14 changes: 14 additions & 0 deletions servermanager/Api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env python
# encoding: utf-8


"""
@version: ??
@author: liangliangyy
@license: MIT Licence
@contact: liangliangyy@gmail.com
@site: https://www.lylinux.org/
@software: PyCharm
@file: __init__.py.py
@time: 2017/8/27 上午11:40
"""
40 changes: 40 additions & 0 deletions servermanager/Api/blogapi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python
# encoding: utf-8


"""
@version: ??
@author: liangliangyy
@license: MIT Licence
@contact: liangliangyy@gmail.com
@site: https://www.lylinux.org/
@software: PyCharm
@file: blogapi.py
@time: 2017/8/27 上午11:40
"""
from blog.models import Article, Category, Tag
from haystack.query import EmptySearchQuerySet, SearchQuerySet


class BlogApi():
def __init__(self):
self.searchqueryset = SearchQuerySet()
self.searchqueryset.auto_query('')
self.__max_takecount__ = 8

def search_articles(self, query):
sqs = self.searchqueryset.auto_query(query)
sqs = sqs.load_all()
return sqs[:self.__max_takecount__]

def get_category_lists(self):
return Category.objects.all()

def get_category_articles(self, categoryname):
articles = Article.objects.filter(category__name=categoryname)
if articles:
return articles[:self.__max_takecount__]
return None

def get_recent_articles(self):
return Article.objects.all()[:self.__max_takecount__]
43 changes: 43 additions & 0 deletions servermanager/Api/commonapi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python
# encoding: utf-8


"""
@version: ??
@author: liangliangyy
@license: MIT Licence
@contact: liangliangyy@gmail.com
@site: https://www.lylinux.org/
@software: PyCharm
@file: commonapi.py
@time: 2017/9/2 上午1:43
"""
import requests
import json
from DjangoBlog.utils import logger


class TuLing():
def __init__(self):
self.__key__ = '2f1446eb0321804291b0a1e217c25bb5'
self.__appid__ = 137762

def __build_req_url(self, content):
return 'http://www.tuling123.com/openapi/api?key=%s&info=%s&userid=%s' % (
self.__key__, content, self.__appid__)

def UserAgent(self, url):
rsp = requests.get(url)
return rsp.content

def getdata(self, content):
requrl = self.__build_req_url(content)
res = self.UserAgent(requrl)
try:
jsons = json.loads(res, encoding='utf-8')
if str(jsons["code"]) == '100000':
return jsons["text"]
except Exception as e:
print(e)
logger.warn(e)
return "哎呀,出错啦。"
45 changes: 45 additions & 0 deletions servermanager/MemcacheStorage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python
# encoding: utf-8


"""
@version: ??
@author: liangliangyy
@license: MIT Licence
@contact: liangliangyy@gmail.com
@site: https://www.lylinux.org/
@software: PyCharm
@file: MemcacheStorage.py
@time: 2017/8/27 上午2:42
"""
from werobot.session import SessionStorage
from werobot.utils import json_loads, json_dumps
from DjangoBlog.utils import cache


class MemcacheStorage(SessionStorage):
def __init__(self, prefix='ws_'):
self.prefix = prefix
self.cache = cache

@property
def is_available(self):
value = "1"
self.set('checkavaliable', value=value)
return value == self.get('checkavaliable')

def key_name(self, s):
return '{prefix}{s}'.format(prefix=self.prefix, s=s)

def get(self, id):
id = self.key_name(id)
session_json = self.cache.get(id) or '{}'
return json_loads(session_json)

def set(self, id, value):
id = self.key_name(id)
self.cache.set(id, json_dumps(value))

def delete(self, id):
id = self.key_name(id)
self.cache.delete(id)
Empty file added servermanager/__init__.py
Empty file.
11 changes: 11 additions & 0 deletions servermanager/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.contrib import admin

# Register your models here.
from .models import commands


class CommandsAdmin(admin.ModelAdmin):
pass


admin.site.register(commands, CommandsAdmin)
5 changes: 5 additions & 0 deletions servermanager/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class ServermanagerConfig(AppConfig):
name = 'servermanager'
Empty file.
17 changes: 17 additions & 0 deletions servermanager/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.db import models


# Create your models here.
class commands(models.Model):
title = models.CharField('命令标题', max_length=300)
command = models.CharField('命令', max_length=2000)
describe = models.CharField('命令描述', max_length=300)
created_time = models.DateTimeField('创建时间', auto_now_add=True)
last_mod_time = models.DateTimeField('修改时间', auto_now=True)

def __str__(self):
return self.title

class Meta:
verbose_name = '命令'
verbose_name_plural = verbose_name

0 comments on commit 09f3e50

Please sign in to comment.