Commit da765292 authored by Roman Shishkin's avatar Roman Shishkin

хочу спать

parent 2f8454c6
from celery.decorators import task
@task
def topic_index(**kwargs):
summary = kwargs.get('summary')
details = kwargs.get('details')
print(summary, details)
BROKER_URL = 'redis://127.0.0.1:6379/5'
CELERY_RESULT_BACKEND = 'redis://127.0.0.1:6379/6'
CELERY_IMPORTS = ("tasks",)
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TIMEZONE = 'Europe/Moscow'
CELERY_ENABLE_UTC = True
daemonize no
dir /storage
save 1 10
maxclients 100
\ No newline at end of file
BROKER_URL = 'redis://127.0.0.1:6589/1'
CELERY_RESULT_BACKEND = 'redis://127.0.0.1:6589/2'
CELERY_IMPORTS = ("tasks",)
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TIMEZONE = 'Europe/Moscow'
CELERY_ENABLE_UTC = True
daemonize no
dir /storage
save 1 10
maxclients 100
port 6589
\ No newline at end of file
......@@ -5,7 +5,7 @@
--project echoes \
--type production \
--blobs "frontend" \
--containers "python redis celery" \
--containers "python" \
--destination /home/ci/lithos/images \
--server lentach.uwtech.org \
--port 2222 \
......
import os
from flask import Flask
from flask import Flask, request
from flask_restful import Api
from .views import api
from .views import root
from .views import uploader
from .resources import init as resources_init
from .jinja import TriangleUndefined, angular_filter
from .utils import get_static_hash
......@@ -23,9 +25,9 @@ def create_app():
app.jinja_env.filters['angular'] = angular_filter
# Register app endpoints
api.init(app)
root.init(app)
uploader.init(app)
resources_init(app)
@app.context_processor
def set_static_hash():
......
......@@ -4,7 +4,7 @@ import string
from numpy import zeros, sum, asarray, log
from numpy.linalg import svd
from porter_stemmer import PorterStemmer
from .porter_stemmer import PorterStemmer
class LatentSemanticAnalyser:
......@@ -123,7 +123,7 @@ class LatentSemanticAnalyser:
index = self.keys.index(index)
print('Слово: «{}», нормальная форма: «{}»'.format(keyword, self.dictionary[self.keys[index]]))
dimensions = 100
dimensions = 5
# Получаем координаты слова
word = (-1 * self.unitary_matrix[:, 1:(dimensions + 1)])[index]
print('Слово: «{}» (№ {}), координаты:\n{}'.format(keyword, index, word))
......@@ -143,7 +143,7 @@ class LatentSemanticAnalyser:
def get_documents(self):
self.prepare()
dimensions = 250
dimensions = 5
results = []
coordinates = -1 * self.transposed_unitary_matrix[1:(dimensions + 1), :]
for i, document in enumerate(self.documents):
......
# coding: utf-8
class TextNormalizer:
def __init__(self):
pass
def normalize(self, text):
for char in list('''«»"'„“”—–-!?,:;.'''):
text = text.replace(char, ' ')
return text
def test_normalize():
text = '«Кайф жгуч: мем колюч!», — сказал мэр; присутстовавшие усмехнулись.'
expected = ' Кайф жгуч мем колюч сказал мэр присутстовавшие усмехнулись '
assert TextNormalizer().normalize(text) == expected
def normalize(self, text):
for char in list('''«»"'„“”—–-!?,:;.'''):
text = text.replace(char, ' ')
return text.lower()
......@@ -3,8 +3,7 @@ from pony import orm
db = orm.Database()
class BlacklistedDomain(db.Entity):
class BlDomain(db.Entity):
domain = orm.Required(str)
class Post(db.Entity):
......@@ -30,5 +29,6 @@ class Photo(db.Entity):
class User(db.Entity):
vk_id = orm.Required(int, unique=True)
balance = orm.Optional(int, sql_default=0)
photos = orm.Set("Photo")
posts = orm.Set("Post")
from flask import abort, request
from flask_restful import Api, Resource, fields, marshal_with
from pony import orm
from .models import BlDomain, Post, PostLink, Photo
from .utils import check_user, get_user_from_db
def init(app):
api = Api(app)
class BlDomainResource(Resource):
@orm.db_session
def get(self, id):
domain = BlDomain.get(id=id)
if domain is None:
abort(404)
else:
return domain.to_dict()
@orm.db_session
def delete(self, id):
BlDomain.get(id=id).delete()
return '', 204
class BlDomainListResource(Resource):
@orm.db_session
def get(self):
domains = BlDomain.select()
return [domain.to_dict() for domain in domains]
@orm.db_session
def post(self):
data = request.get_json()
BlDomain(
domain=data.get('domain')
)
return data
class PostResource(Resource):
@orm.db_session
def get(self, id):
post = Post.get(id=id)
if post is None:
abort(404)
else:
return {
'id': post.id,
'summary': post.summary,
'text': post.text,
'links': [link.to_dict() for link in post.links],
'photos': [{
'id': photo.id,
'url': photo.url,
'latitude': photo.latitude,
'longitude': photo.longitude,
'timestamp': photo.timestamp.isoformat()
} for photo in post.photos],
'user': post.user.to_dict(),
'state': post.state,
}
@orm.db_session
def delete(self, id):
Post.get(id=id).delete()
return '', 204
class PostListResource(Resource):
@orm.db_session
def get(self):
posts = Post.select()
return [{
'id': post.id,
'summary': post.summary,
'text': post.text,
'links': [link.to_dict() for link in post.links],
'photos': [{
'id': photo.id,
'url': photo.url,
'latitude': photo.latitude,
'longitude': photo.longitude,
'timestamp': photo.timestamp.isoformat()
} for photo in post.photos],
'user': post.user.to_dict(),
'state': post.state,
} for post in posts]
@orm.db_session
def post(self):
data = request.get_json()
app_id = app.config['APP_ID']
app_secret = app.config['APP_SECRET']
user_id = data.get('user_id')
user_key = data.get('user_key')
if not check_user(app_id, user_id, app_secret, user_key):
abort(403)
choices = data.get('choices', None)
files = data.get('files', None)
post = Post(
summary=data.get('summary'),
text=data.get('text', ''),
user=get_user_from_db(user_id)
)
orm.commit()
if choices is not None:
for choice in choices:
PostLink(link=choice['url'], post=post)
if files is not None:
for file in files:
photo = Photo[file['id']]
photo.post = post
return data
class UserPostListResource(Resource):
@orm.db_session
def get(self, user_id):
posts = Post.select(lambda p: p.user.id == user_id)
return [{
'id': post.id,
'summary': post.summary,
'text': post.text,
'links': [link.to_dict() for link in post.links],
'photos': [{
'id': photo.id,
'url': photo.url,
'latitude': photo.latitude,
'longitude': photo.longitude,
'timestamp': photo.timestamp.isoformat()
} for photo in post.photos],
'user': post.user.to_dict(),
'state': post.state,
} for post in posts]
api.add_resource(BlDomainListResource, '/api/bldomains')
api.add_resource(BlDomainResource, '/api/bldomains/<string:id>')
api.add_resource(PostListResource, '/api/posts')
api.add_resource(PostResource, '/api/posts/<string:id>')
api.add_resource(UserPostListResource, '/api/users/<string:user_id>/posts')
......@@ -28,7 +28,8 @@
<div class="container-fluid" ng-controller="SubmitController">
<!-- Пользователь -->
<div class="row user-row">
<div class="user-row__avatar"><img></div>
<div class="user-row__avatar"><img src="{{user.photo_50}}"></div>
<div class="user-row__name">{{user.first_name}} {{user.last_name}}</div>
</div>
<!-- Меню -->
<div class="row">
......
# coding=utf-8
import json
import datetime
from flask import request
from pony import orm
from ..root import check_user
from ...models import Post, PostLink, Photo
from ...utils import get_user_from_db
date_handler = lambda obj: (
obj.isoformat()
if isinstance(obj, datetime.datetime) or isinstance(obj, datetime.date)
else None
)
def init(app):
@app.route('/api/posts', methods=['GET'])
@orm.db_session
......@@ -35,11 +42,12 @@ def init(app):
user_id = request_json.get('user_id', None)
user_key = request_json.get('user_key', None)
links = request_json.get('links', None)
print(links)
files = request_json.get('files', None)
if not check_user(app_id, user_id, app_secret, user_key):
return json.dumps({
'error': True,
'message': 'please provide VK user credentials'
'message': 'Please provide VK user credentials'
})
user = get_user_from_db(user_id)
post = Post(summary=request_json.get('summary', None),
......@@ -51,6 +59,9 @@ def init(app):
# TODO check for the blacklist
lnk = PostLink(link=link, post=post)
for file in files:
Photo[file['id']].post = post
orm.commit()
return json.dumps({
'error': False,
......@@ -61,58 +72,37 @@ def init(app):
})
@app.route('/api/posts/<int:id>', methods=['GET'])
@orm.db_session
def api_posts_get(id):
try:
post = Post[id]
return json.dumps({
'status': 'ok',
'data': {
'id': post.id,
'summary': post.summary,
'details': post.details,
'source': post.source,
'photo': post.photo,
'video': post.video,
'location': {
'latitude': post.latitude,
'longitude': post.longitude,
},
'author': post.author,
'state': post.state,
}
})
'error': False,
'data': post.to_dict(),
'links': [link for link in post.links],
'photos': [{
'id': photo.id,
'url': photo.url
} for photo in post.photos]
}, default=date_handler)
except orm.core.ObjectNotFound:
return json.dumps({
'status': 'error',
'error': {
'type': 'object_not_found',
'message': 'post with specified identifier not found',
'erroneous_id': id,
}
'error': True,
'message': 'Post with specified identifier not found'
})
@app.route('/api/posts/<int:id>', methods=['PATCH'])
def api_posts_patch(id):
request_json = request.get_json()
# TODO: Update data in database
return json.dumps({
'status': 'ok',
})
@app.route('/api/posts/<int:id>', methods=['DELETE'])
@orm.db_session
def api_posts_delete(id):
try:
Post[id].delete()
return json.dumps({
'status': 'ok',
'error': False,
})
except orm.core.ObjectNotFound:
return json.dumps({
'status': 'error',
'error': {
'type': 'object_not_found',
'message': 'post with specified identifier not found',
'erroneous_id': id,
}
'error': True,
'message': 'Post with specified identifier not found'
})
from flask import render_template, request, redirect, url_for
from flask import render_template, request, redirect, url_for, g
from ..utils import check_user, get_user_from_db
from vklancer import api
......@@ -25,7 +25,9 @@ def init(app):
def submit(id, key):
if check_user(app.config['APP_ID'], id, app.config['APP_SECRET'], key) is False:
return render_template('error.html')
return render_template('submit.html', id=id, key=key)
vk = api.API()
user = vk.users.get(user_ids=id, fields='has_photo,photo_50')
return render_template('submit.html', id=id, key=key, user=user['response'][0])
@app.route('/admin/<int:id>/<string:key>')
def admin(id, key):
......@@ -39,13 +41,13 @@ def init(app):
return render_template('error.html')
return render_template('editor.html', id=id, key=key)
if app.config['DEBUG']:
@app.route('/submit')
def submit_dev():
vk = api.API()
user = vk.users.get(user_ids=1, fields='has_photo,photo_50')
print(user)
return render_template('submit.html', id=1, key='d666f7eddb8aa15092c48c64bff6c7d4')
return render_template('submit.html', id=1, key='d666f7eddb8aa15092c48c64bff6c7d4', user=user['response'][0])
@app.route('/admin')
def admin_dev():
......
class BannedSitesController {
constructor($scope, $http) {
$scope.loadItems = () => {
$http.get('/api/blacklist').then(function (response) {
$scope.items = response.data.data;
$http.get('/api/bldomains').then(function (response) {
$scope.items = response.data;
});
};
$scope.addItem = () => {
$http.post('/api/blacklist', { domain: $scope.domain }).then(function successCallback(response) {
$http.post('/api/bldomains', { domain: $scope.domain }).then(function successCallback(response) {
$scope.loadItems();
$scope.domain = '';
}, function errorCallback(response) {
......@@ -16,8 +16,7 @@ class BannedSitesController {
};
$scope.deleteItem = (id) => {
alert(id);
$http.delete('/api/blacklist/' + id).then(function successCallback(response) {
$http.delete('/api/bldomains/' + id).then(function successCallback(response) {
$scope.loadItems();
}, function errorCallback(response) {
console.log('err');
......
......@@ -3,28 +3,24 @@ class CreateController {
$scope.flash_info = false;
$scope.flash_danger = false;
$scope.link = ["", "", "", "", ""];
$scope.contents = [];
$scope.files = [];
let number = 1;
let max = 4;
let value = "Дополнительное поле для ссылки";
$scope.show = (id) => {
if (number <= max && $scope.link[number - 1].length === 1) {
$scope.contents.push({number: number, name: "link" + number, value: value});
number++;
}
if ($scope.link[id].length === 0 && id > 0 && (id === $scope.contents.length - 1) && ($scope.link[id + 1].length === 0)) {
$scope.contents.pop();
number--;
}
$scope.choices = [];
$scope.addNewChoice = function() {
if ($scope.choices.length === 5) return;
let newItemNo = $scope.choices.length+1;
$scope.choices.push({'id':'link'+newItemNo});
};
$scope.removeChoice = function() {
let lastItem = $scope.choices.length-1;
$scope.choices.splice(lastItem);
};
$scope.send = () => {
let data = {
summary: $scope.summary,
links: $scope.link,
choices: $scope.choices,
text: $scope.text,
files: $scope.files,
......@@ -34,22 +30,13 @@ class CreateController {
$http.post('/api/posts', data).then(function successCallback(response) {
$scope.summary = '';
$scope.link[0] = '';
$scope.link[1] = '';
$scope.link[2] = '';
$scope.link[3] = '';
$scope.link[4] = '';
$scope.text = '';
$scope.files = [];
$scope.choices = [];
if (response.data.error === false) {
$scope.flash_danger = false;
$scope.flash_text = response.data.message;
$scope.flash_info = true;
} else {
$scope.flash_info = false;
$scope.flash_text = response.data.message;
$scope.flash_danger = true;
}
$scope.flash_danger = false;
$scope.flash_text = 'Пост успешно отправлен!';
$scope.flash_info = true;
}, function errorCallback(response) {
$scope.flash_info = false;
......
class HistoryController {
constructor($scope, $location) {
$scope.isRouteActive = function(route) {
let curRoute = $location.path();
return curRoute.match(route);
}
constructor($scope, $http) {
$scope.data = false;
$scope.loadItems = () => {
$http.get('/api/users/'+user_id+'/posts').then(function (response) {
$scope.items = response.data;
});
};
$scope.setItem = (item) => {
$scope.data = item;
console.log(item);
};
$scope.loadItems();
}
}
HistoryController.$inject = ['$scope', '$location'];
HistoryController.$inject = ['$scope', '$http'];
export default HistoryController;
\ No newline at end of file
......@@ -14,13 +14,13 @@
</div>
<div class="input-group">
<label for="link0">
Ссылки (не более 5):
<label>
Ссылки (не более 5): <a class="btn btn-xs btn-primary addfields" ng-click="addNewChoice()">Добавить поле</a>
</label>
<input type="text" ng-model="link[0]" ng-change="show(0)" name="link0" id="link0" class="form-control" placeholder="Ссылки на источники, издания или ресурсы">
<div ng-repeat="content in contents">
<input type="text" ng-model="link[content.number]" ng-change="show(content.number)" class="form-control" name="{{content.name}}" placeholder="{{content.value}}"/>
</div>
<fieldset data-ng-repeat="choice in choices">
<input type="text" class="form-control" ng-model="choice.url" name="" placeholder="Введите адрес ссылки" style="width: 90%">
<button class="btn btn-danger btn-small remove" ng-show="$last" ng-click="removeChoice()">-</button>
</fieldset>
</div>
<div class="input-group">
......
<div class="col-md-12 listview">
<div class="col-md-3 listview__sidebar">
<div class="list-group">
<a ng-click="alert(1);" class="list-group-item active">
<p class="list-group-item-text">TEXT TEXT TEXT</p>
</a>
<a ng-click="alert(1);" class="list-group-item">
<p class="list-group-item-text">TEXT TEXT TEXT</p>
</a>
<a ng-click="alert(1);" class="list-group-item">
<p class="list-group-item-text">TEXT TEXT TEXT</p>
</a>
<a ng-click="alert(1);" class="list-group-item">
<p class="list-group-item-text">TEXT TEXT TEXT</p>
</a>
<a ng-click="alert(1);" class="list-group-item">
<p class="list-group-item-text">TEXT TEXT TEXT</p>
<a class="list-group-item" ng-repeat="item in items" ng-click="setItem(item);">
<p class="list-group-item-text">{{item.summary}}</p>
</a>
</div>
</div>
<div class="col-md-9 listview__content">
<div class="col-md-9 listview__content" ng-show="data">
<div class="col-md-12">
<div class="showItem">
<label>Описание:</label>
<div class="panel panel-default">
<div class="panel-body">
.....
{{data.summary}}
</div>
</div>
</div>
<div class="showItem">
<label>Ссылки:</label>
<div class="panel panel-default">
<div class="panel-body">
.....
<div ng-repeat="link in data.links">
<a href="{{link.link}}">{{link.link}}</a>
</div>
</div>
</div>
</div>
<div class="showItem">
<label>Изображения:</label>
<div class="panel panel-default">
<div class="panel-body">
<div class="image-list">
<div ng-repeat="photo in data.photos" class="image-list__container">
<a target="_blank" href="{{photo.url}}"><img src="{{photo.url}}" class="image-list__image thumbnail"></a>
</div>
</div>
</div>
</div>