Commit b768015d authored by lixiaofang's avatar lixiaofang

Merge branch 'majia' into test

parents b2de49b4 69f8e88c
......@@ -24,5 +24,29 @@
<option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" />
</formatting-settings>
</DBN-SQL>
<DBN-PSQL>
<case-options enabled="false">
<option name="KEYWORD_CASE" value="lower" />
<option name="FUNCTION_CASE" value="lower" />
<option name="PARAMETER_CASE" value="lower" />
<option name="DATATYPE_CASE" value="lower" />
<option name="OBJECT_CASE" value="preserve" />
</case-options>
<formatting-settings enabled="false" />
</DBN-PSQL>
<DBN-SQL>
<case-options enabled="false">
<option name="KEYWORD_CASE" value="lower" />
<option name="FUNCTION_CASE" value="lower" />
<option name="PARAMETER_CASE" value="lower" />
<option name="DATATYPE_CASE" value="lower" />
<option name="OBJECT_CASE" value="preserve" />
</case-options>
<formatting-settings enabled="false">
<option name="STATEMENT_SPACING" value="one_line" />
<option name="CLAUSE_CHOP_DOWN" value="chop_down_if_statement_long" />
<option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" />
</formatting-settings>
</DBN-SQL>
</code_scheme>
</component>
\ No newline at end of file
# -*- coding: UTF-8 -*-
import logging
import traceback
import json
from celery import shared_task
from django.conf import settings
from django.core import serializers
from trans2es.type_info import get_type_info_map
# from rpc.all import get_rpc_remote_invoker
from libs.es import ESPerform
import logging
import traceback
from libs.cache import redis_client
from trans2es.models.face_user_contrast_similar import FaceUserContrastSimilar,UserSimilarScore
import json
from linucb.utils.register_user_tag import RegisterUserTag
@shared_task
......
from django.apps import AppConfig
class majiaConfig(AppConfig):
name = "majia"
verbose_name = "马甲用户"
# -*- coding: UTF-8 -*-
import requests
import time
import datetime
import pymysql
import random
import pandas as pd
import traceback
from log_settings import *
import logging
from django.conf import settings
from get_session import get_comments, get_cookies, click, time_conv, login, reply
@shared_task
def auto_click(es_type, id):
try:
pc = pymysql.connect(host=host, user=user, passwd=passwd, db=db, port=3306)
cursor = pc.cursor()
cursor.execute(
"SELECT id,user_id FROM topic WHERE id = " + str(
id) + " and user_id in (select user_id from user_extra where is_shadow = 0)")
data = cursor.fetchall()
topic_id_list = list(data)
logging.info("Database version : %s " % topic_id_list)
pc.close()
topic_id_list = 919337
exec_count = 0
if topic_id_list:
def fun_timer():
cookies = login()
if cookies:
click(cookies, topic_id_list[0])
global timer
global exec_count
exec_count += 1
if exec_count == 1:
# sleep_time = random.randint(300, 540)
sleep_time = 30
timer = threading.Timer(sleep_time, fun_timer)
timer.start()
if exec_count == 2:
# sleep_time = random.randint(1000, 1900)
sleep_time = 50
timer = threading.Timer(sleep_time, fun_timer)
timer.start()
sleep_time = random.randint(300, 540)
timer = threading.Timer(10, fun_comment) # 首次启动
timer.start()
sleep_time = random.randint(300, 540)
timer = threading.Timer(10, fun_timer) # 首次启动
timer.start()
else:
pass
except:
logging.error("catch exception,main:%s" % traceback.format_exc())
@shared_task
def auto_reply(es_type,id):
try:
pc = pymysql.connect(host=host, user=user, passwd=passwd, db=db, port=3306)
cursor = pc.cursor()
cursor.execute(
"SELECT id,user_id FROM topic WHERE id = " + str(
id) + " and user_id in (select user_id from user_extra where is_shadow = 0)")
data = cursor.fetchall()
topic_id_list = list(data)
logging.info("Database version : %s " % topic_id_list)
pc.close()
topic_id_list = 919337
exec_count = 0
if topic_id_list:
def fun_comment():
cookies = login()
if cookies:
comment_content = get_comments()
comment = comment_content[0]
reply(cookies, id, comment)
global timer
global exec_count
exec_count += 1
if exec_count == 1:
sleep_time = random.randint(300, 540)
sleep_time = 30
timer = threading.Timer(sleep_time, fun_comment)
timer.start()
if exec_count == 2:
sleep_time = random.randint(1000, 1900)
sleep_time = 30
timer = threading.Timer(sleep_time, fun_comment)
timer.start()
sleep_time = random.randint(300, 540)
timer = threading.Timer(10, fun_comment) # 首次启动
timer.start()
except:
logging.error("catch exception,main:%s" % traceback.format_exc())
import requests
import time
import datetime
import random
import traceback
auto_click_url = "http://earth.igengmei.com/api/v1/like"
auto_reply_url = "http://earth.igengmei.com/api/v1/reply/create"
auto_follow_url = "http://earth.igengmei.com/api/v1/follow"
auto_urge_url = "http://earth.igengmei.com/api/v1/user/urge"
def get_majia():
try:
data = open("/srv/apps/cybertron/majia_email.txt")
list = []
for i in data:
list.append(i.strip('\n').strip(','))
maj = random.randint(1, len(list))
user_id = list[maj - 1]
return user_id
except:
logging.error("catch exception,get_majia:%s" % traceback.format_exc())
return None
def get_cookies(user_id):
try:
with open("/srv/apps/cybertron/user_session.txt", 'r') as f:
try:
data = f.readlines()
except:
data = None
list = []
for i in data:
list.append(i.strip('\n').split(","))
for i in list:
if user_id == i[0]:
return (i[1])
except:
return None
def login():
try:
user_id = get_majia()
cookies = get_cookies(user_id)
if cookies is not None:
return {'sessionid': cookies}
except:
logging.error("catch exception,logins:%s" % traceback.format_exc())
return None
def click(cookies_get,id):
try:
post_dict = {
'type': 0,
'id': id
}
response = requests.post(url=auto_click_url,
cookies=cookies_get,
data=post_dict)
logging.info("response.text:%s" % response.text)
except:
logging.error("catch exception,logins:%s" % traceback.format_exc())
def reply(cookies_get, id, content):
try:
post_dict = {
'topic_id': id,
'content': content
}
response = requests.post(url=auto_reply_url,
cookies=cookies_get,
data=post_dict)
logging.info("response.text:%s" % response.text)
except:
logging.error("catch exception,logins:%s" % traceback.format_exc())
def time_conv(minutest):
try:
now = datetime.datetime.now()
yes_time = now - datetime.timedelta(minutes=minutest)
print(yes_time)
return yes_time
except:
return None
def get_comments():
try:
data = open("/srv/apps/cybertron/offline_comment.txt", "r")
list_guanshui = []
for i in data:
list_guanshui.append(i)
num1 = random.randint(0, 30)
num2 = random.randint(30, 70)
num4 = random.randint(70, len(list_guanshui))
comment1 = list_guanshui[num1 - 1]
comment2 = list_guanshui[num2 - 1]
comment3 = list_guanshui[num3 - 1]
comment_list = [comment1, comment2, comment3]
return comment_list
except:
return None
This diff is collapsed.
import requests
import traceback
import logging
from celery import shared_task
login_url = "http://earth.igengmei.com/api/account/login_pwd"
def index_first():
try:
r1 = requests.get(login_url)
return r1.cookies.get_dict()
except:
logging.error("index_first:%s" % traceback.format_exc())
return None
@shared_task(name="majia.tasks.get_cook")
def get_cook():
data = open("physical/majia/majia_email.txt","r")
list = []
dicts = {}
for i in data:
list.append(i.strip('\n').strip(','))
for i in list:
cookies = index_first()
post_dict = {
'account_type': 2,
'pwd': '123456',
'email': i
}
response = requests.post(
url=login_url,
data=post_dict,
cookies=cookies
)
headers = response.headers
print(response.text)
cook = headers['Set-Cookie'].split(";")
cook = cook[0].split('=')[1]
logging.info("response.text :%s" % response.text)
dicts[i] = cook
with open("user_session.txt", 'w') as f:
for key, value in dicts.items():
f.write(key)
f.write(",")
f.write(value)
f.write("\n")
# coding=utf-8
from __future__ import unicode_literals, print_function, absolute_import
import itertools
from django.conf import settings
import itertools
import logging
class CeleryTaskRouter(object):
queue_task_map = {
"tapir-alpha": [
'injection.data_sync.tasks.write_to_es',
]
],
# "majia-alpha": [
# 'injection.data_sync.auto_instant_click.auto_click',
# ],
# "majia-alpha": [
# 'injection.data_sync.auto_instant_click.auto_reply',
# ]
}
# Map[TaskName, QueueName]
task_queue_map = dict(itertools.chain.from_iterable(
[(task, queue) for task in task_list]
......
......@@ -48,6 +48,7 @@ INSTALLED_APPS = (
'trans2es',
'search',
'injection.data_sync',
'majia.apps.majiaConfig',
)
CELERYBEAT_SCHEDULE = {
......@@ -57,6 +58,7 @@ CELERYBEAT_SCHEDULE = {
'args': ()
},
}
"""
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment