Conflicts:
	fetchQzone/models.py
	fetchQzone/static/fetchQzone/basic.js
	fetchQzone/templates/fetchQzone/base.html
	fetchQzone/templates/fetchQzone/base_allfeeds.html
	fetchQzone/templates/fetchQzone/base_onefeed.html
	fetchQzone/tests.py
	fetchQzone/urls.py
	fetchQzone/views.py
	mysite/settings.py
	mysite/urls.py
This commit is contained in:
zhangxu1573@qq.com
2015-02-28 16:54:10 +08:00
15 changed files with 110 additions and 7 deletions
+6
View File
@@ -0,0 +1,6 @@
# fetchQzone
抓取多人QQ空间说说和评论。以便分析一个人在他的好友的空间中留下的轨迹,获取有用信息。
部署在百度云上,详情及demo请移步:[http://ncwugirl.duapp.com/fetchQzone/search2/?user=738285867](http://ncwugirl.duapp.com/fetchQzone/search2/?user=738285867)
,
使用Python/django/MySQL/开发
+9 -2
View File
@@ -4,13 +4,16 @@ from django.db import models
class people(models.Model):
"""docstring for people"""
qq=models.BigIntegerField(primary_key=True);
#nick=models.CharField(max_length=30)
class feed(models.Model):
"""docstring for feed"""
feedID=models.CharField(max_length=255,primary_key=True);
userID=models.ForeignKey(people);
time=models.BigIntegerField();
<<<<<<< HEAD
info=models.TextField(null=True,blank=True);
=======
info=models.TextField();
>>>>>>> fc87b078bf56697fa825af928909cbfee5fe787b
commentNum=models.IntegerField();
likeNum=models.IntegerField();
visitTime=models.BigIntegerField();
@@ -23,9 +26,13 @@ class comment(models.Model):
come=models.ForeignKey(people,related_name='come');
to=models.ForeignKey(people,related_name='to');
time=models.BigIntegerField();
<<<<<<< HEAD
info=models.TextField(null=True,blank=True);
class nick(models.Model):
"""de"""
host=models.ForeignKey(people,related_name='host');
guest=models.ForeignKey(people,related_name='guest');
nick=models.CharField(max_length=30);
nick=models.CharField(max_length=30);
=======
info=models.TextField();
>>>>>>> fc87b078bf56697fa825af928909cbfee5fe787b
+2
View File
@@ -31,6 +31,7 @@ function convertTime (now,time) {
if(cut<daymillisec)
{
if (now.getDate()==time.getDate())
return HourMin;
else
return '昨天'+' '+HourMin;
@@ -38,6 +39,7 @@ function convertTime (now,time) {
else if (cut<daymillisec*2)
{
if (now.getDate()-time.getDate()==1)
return '昨天'+' '+HourMin;
else
return MonthDayHM;
@@ -17,12 +17,14 @@ em{
</head>
<body>
<div id="headtitle">{% block innertitle %}{{params.user_nick}}的说说和评论{% endblock innertitle %}</div>
{% block search %}
<form>
&nbsp;&nbsp;QQ号:<input name='user' ><br><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type="submit"> 搜索</button>
</form>
{% endblock search %}
{% block friend %}
<h4>&nbsp;&nbsp;<a href="?user={{params.user}}">{{params.user_nick}}</a>与以下同学互动较多:<br></h4>
@@ -32,6 +34,7 @@ em{
<strong>{{nick|default:qq}}({{cnt}})</strong>
{% else %}
<a href="?user={{params.user}}&friend={{qq}}">{{nick|default:qq}}({{cnt}})</a>
{% endif %}
{% if forloop.counter|divisibleby:"5" %}
<br><br>
@@ -44,6 +47,7 @@ em{
{% endblock discribe %}
{% block fenye %}
<p id='page'>
{% if params.last >= 0 %}
@@ -68,15 +72,18 @@ em{
&nbsp;&nbsp;&nbsp;&nbsp;来自:<a href="?user={{userID_id}}">{{nick}}</a>&nbsp;&nbsp;时间:<div class='times' style='display: inline-block'>{{times}}</div>&nbsp;&nbsp;{% block detail %}<a href="/fetchQzone/onefeed?feedID={{feedID}}">详细</a>{% endblock detail %}</h5>
</div>
{% for parent,come,to,info,timesss,rootID,come_nick,to_nick in comments %}
{% if parent == feedID %}
<div class="comment">
{% if rootID == -1 %}
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="?user={{come}}">{{come_nick|default:come}}</a>
{% else %}
&nbsp;&nbsp;&nbsp;&nbsp;<a href="?user={{come}}">{{come_nick|default:come}}</a>
回复&nbsp;
<a href="?user={{to}}">{{to_nick|default:to }}</a>
{% endif %}
{{info|safe}}
</div>
@@ -4,4 +4,4 @@
{% endblock title %}
{% block discribe %}
<h4><em>{{params.user_nick}}</em>&nbsp;&nbsp;发出的说说:</h4>
{% endblock discribe %}
{% endblock discribe %}
@@ -16,6 +16,7 @@
{% endblock search %}
{% block friend %}
{% endblock friend %}
{% block feed %}
{% for info,times,userID_id,feedID,nick in feeds %}
@@ -42,4 +43,4 @@
{% empty %}
<div id="headtitle">木有了~~~~看完了/(ㄒoㄒ)/~~*^_^* …… *^_^*</div>
{% endfor %}
{% endblock feed %}
{% endblock feed %}
+1
View File
@@ -6,4 +6,5 @@ urlpatterns=patterns('',
url(r'^$',views.search),
url(r'^onefeed/$',views.feedDetail),
url(r'^nick/$',views.getnick),
)
+80 -1
View File
@@ -2,13 +2,20 @@
from django.shortcuts import render
from django.shortcuts import get_object_or_404,render
from django.http import HttpResponseRedirect,HttpResponse
<<<<<<< HEAD
from fetchQzone.models import comment,feed,people,nick
from django.db import connection
=======
from fetchQzone.models import comment,feed,people
from django.db import connection
>>>>>>> fc87b078bf56697fa825af928909cbfee5fe787b
from django import forms
import copy
import time
import json
import urllib2
<<<<<<< HEAD
from fetchQzone import querytool
def upload(request):
print('1111111111111')
@@ -56,6 +63,37 @@ def upload(request):
pass
'''
=======
# Create your views here.
def upload(request):
shuo=request.POST['shuo']
shuo=urllib2.unquote(shuo)
shuo=json.loads(shuo)
print(shuo['feed'][1])
print(shuo['owner'])
peo=people(qq=int(shuo['owner']))
peo.save()
for x in shuo['people']:
ppeo=people(qq=int(x))
ppeo.save()
for x in shuo['feed']:
try:
peo=people(qq=int(x['userID']))
fe=feed(feedID=x['feedID'],info=x['info'],likeNum=int(x['likeNum']),time=int(x['time']),userID=peo,visitTime=int(x['visitTime']),commentNum=int(x['commentNum']))
fe.save()
except :
print("error in save feed")
for x in shuo['comment']:
fe=feed(feedID=x['parent'])
peo_come=people(qq=int(x['from']))
peo_to=people(qq=int(x['to']))
comm=comment(IDinFeed=x['IDinFeed'],parent=fe,come=peo_come,to=peo_to,rootID=x['rootID'],time=int(x['time']),info=x['info'])
comm.save()
>>>>>>> fc87b078bf56697fa825af928909cbfee5fe787b
return HttpResponse('OKKKKK')
def search(request):
@@ -75,14 +113,19 @@ def search(request):
a['strong']=True
fenye.append(a)
params={'last':start-num,'num':num,'next':start+num}
<<<<<<< HEAD
#处理user,friend参数
friend=None;
=======
#处理user 参数
>>>>>>> fc87b078bf56697fa825af928909cbfee5fe787b
try:
user=int(request.GET['user'])
params['user']=user
except :
info='您的请求有误'
return HttpResponse(info+'wrong!!!',status=404)
<<<<<<< HEAD
try:
friend=int(request.GET['friend'])
params['friend']=friend
@@ -109,12 +152,38 @@ def search(request):
else:
Template='fetchQzone/feedwithfriend.html'
return render(request,Template,reslut)
=======
#处理friend 参数
try:
friend=int(request.GET['friend'])
sql_feed="select distinct fetchQzone_feed.info,fetchQzone_feed.time,fetchQzone_feed.userID_id,fetchQzone_feed.feedID from fetchQzone_comment,fetchQzone_feed where ((come_id=%s AND to_id=%s) OR (come_id=%s AND to_id=%s) ) AND fetchQzone_comment.parent_id=fetchQzone_feed.feedID order by fetchQzone_feed.userID_id,fetchQzone_feed.time desc limit %s,%s"%(user,friend,friend,user,start,num)
sql_comment="select distinct parent_id,come_id,to_id,info,fetchQzone_comment.time,rootID from fetchQzone_comment where ((come_id=%s AND to_id=%s) OR (come_id=%s AND to_id=%s)) order by fetchQzone_comment.parent_id,fetchQzone_comment.IDinfeed"% (user,friend,friend,user)
sql_friend="select uni.qq,count(1) as cnt from (select come_id as qq from fetchQzone_comment where to_id=%s union all select to_id as qq from fetchQzone_comment where come_id=%s )uni where qq!=%s group by uni.qq order by cnt desc limit 0,15"%(user,user,user)
params['friend']=friend
except :
sql_feed="select distinct fetchQzone_feed.info,fetchQzone_feed.time,fetchQzone_feed.userID_id,fetchQzone_feed.feedID from fetchQzone_feed where fetchQzone_feed.userID_id=%s order by fetchQzone_feed.time desc limit %s,%s"%(user,start,num)
sql_comment="select distinct parent_id,come_id,to_id,fetchQzone_comment.info,fetchQzone_comment.time,rootID from fetchQzone_comment,("+sql_feed+")fe where fetchQzone_comment.parent_id=fe.feedID order by fetchQzone_comment.parent_id,fetchQzone_comment.IDinfeed"
sql_friend="select uni.qq,count(1) as cnt from (select come_id as qq from fetchQzone_comment where to_id=%s union all select to_id as qq from fetchQzone_comment where come_id=%s )uni where qq!=%s group by uni.qq order by cnt desc limit 0,15"%(user,user,user)
cursor = connection.cursor()
#得到评论List,装配结果
cursor.execute(sql_comment)
comments=cursor.fetchall()
#得到说说List,
cursor.execute(sql_feed)
feeds=cursor.fetchall()
#得到朋友们列表
cursor.execute(sql_friend)
friends=cursor.fetchall()
#return [feeds,comments,sql_feed,sql_comment]
return render(request,'fetchQzone/base_allfeeds.html',{'feeds':feeds,'comments':comments,'friend':friends,'fenye':fenye,'params':params})
>>>>>>> fc87b078bf56697fa825af928909cbfee5fe787b
def feedDetail(request):
try:
feedID=request.GET["feedID"]
except :
return HttpResponse("wrong~~~")
<<<<<<< HEAD
Result=querytool.getFeedDetail(feedID)
return render(request,'fetchQzone/base_onefeed.html',Result)
def index(request):
@@ -136,4 +205,14 @@ def getnick(request):
cont+=(str(x.host.qq)+" :~~~ "+str(x.guest.qq)+":%% "+str(x.nick)+"<br>")
#return HttpResponse(cont)
'''
return render(request,'fetchQzone/index.html')
return render(request,'fetchQzone/index.html')
=======
sql_feed="select fetchQzone_feed.info,fetchQzone_feed.time,fetchQzone_feed.userID_id ,fetchQzone_feed.feedID from fetchQzone_feed where fetchQzone_feed.feedID='%s' "% feedID
sql_comment="select distinct parent_id,come_id,to_id,info,fetchQzone_comment.time,rootID from fetchQzone_comment where parent_id='%s' order by IDinFeed "% feedID
cursor = connection.cursor()
cursor.execute(sql_comment)
comments=cursor.fetchall()
cursor.execute(sql_feed)
feeds=cursor.fetchall()
return render(request,'fetchQzone/base_onefeed.html',{'feeds':feeds,'comments':comments})
>>>>>>> fc87b078bf56697fa825af928909cbfee5fe787b
Binary file not shown.
Binary file not shown.
+1 -2
View File
@@ -79,13 +79,12 @@ STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
#STATIC_URL = 'http://ncwugirl.qiniudn.com/'
#DOMAIN
domain="www.ncwugirl.duapp.com"
STATIC_URL = '/static/'
QINIU_URL='http://ncwugirl.qiniudn.com/'
# Additional locations of static files
STATICFILES_DIRS = ('http://ncwugirl.qiniudn.com/',
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
Binary file not shown.
+1
View File
@@ -8,6 +8,7 @@ admin.autodiscover()
urlpatterns = patterns('',
# Examples:
url(r'^$', 'fetchQzone.views.index', name='home'),
# url(r'^mysite/', include('mysite.foo.urls')),
#Uncomment the admin/doc line below to enable admin documentation:
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.