-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from liangliangyy/weixin
增加微信功能
- Loading branch information
Showing
20 changed files
with
528 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
dist: precise | ||
language: python | ||
python: | ||
- "3.4" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "哎呀,出错啦。" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.