예제 #1
0
def formdata(links):
    data=[]
    for i in links:
        try:
            html=requests.get(i).text
            soup=sp(html,'lxml')
            url=i
            title=soup.find('title').text
            tag=''
            category=''
            try:
                tag=getTagAndCateByLink(i,'Tags')
            except Exception:
                pass
            try:
                category=getTagAndCateByLink(i,'Categories')
            except Exception:
                pass
            try:
                catchhtml=soup.find(id='cnblogs_post_body')
                catchhtml=str(catchhtml)
                data.append(article(url, title, catchhtml,tag,category))
            except Exception:
                print(i+' has no main')
        except Exception as e:
            print e
    return data
예제 #2
0
def success_page(request):
    ai = request.session.get("author_id")
    aname = request.session.get("author_name")
    aemail = request.session.get("author_email")
    a = author_signup(aid=ai, author_name=aname, email=aemail)
    at = article(uid=a, title=request.POST["title"], content=request.POST["content"], pub_date=timezone.now())
    at.save()
    return render(request, "success.html", {"art": at})
예제 #3
0
def AddTextFileToDB(filename):
  with open(filename, "r") as textfile:
    url = textfile.readline()
    date = textfile.readline()
    score = textfile.readline()
    magnitude = textfile.readline()
    article_content = textfile.read()
    article_file = article(title=url,date=date,score=score, magnitude=magnitude, article_content=article_content)
    article_file.save()
예제 #4
0
 def setUp(self):
     '''
     Set up method that will run before every Test
     '''
     self.new_article = article(
         'null', 'Forbes.com', 'Billy Bambrough, Contributor',
         'Twitter CEO Jack Dorsey Has Made A Bold Prediction About Bitcoin',
         'https://www.forbes.com/sites/billybambrough/2019/02/04/twitter-ceo-jack-dorsey-has-made-a-bold-prediction-about-bitcoin/',
         '2019-02-04T06:10:00Z')
예제 #5
0
def getDocList(file):    
    doclist=[];
    r=re.compile("标 题:")
    b=re.compile(" ")
    c="first";
    art= article()
    art.title=c
    art.text=""
    for line in file.readlines():
        m=r.match(line)
        if m :
            print line+",,,,,,,,,,,,,,,,,,,,,,"
            z= r.sub("",line)
            c=b.sub("",z)
            doclist.append(art);
            art=article()
            art.title=c
            art.text=""
        else:
            line=b.sub("",line)                
            art.text=art.text+line
    doclist.append(art);
    return doclist
예제 #6
0
def getDocList(file):
    doclist = []
    r = re.compile("标 题:")
    b = re.compile(" ")
    c = "first"
    art = article()
    art.title = c
    art.text = ""
    for line in file.readlines():
        m = r.match(line)
        if m:
            print line + ",,,,,,,,,,,,,,,,,,,,,,"
            z = r.sub("", line)
            c = b.sub("", z)
            doclist.append(art)
            art = article()
            art.title = c
            art.text = ""
        else:
            line = b.sub("", line)
            art.text = art.text + line
    doclist.append(art)
    return doclist
예제 #7
0
 def post(self, request):
     form = articleForm(request.POST)
     if form.is_valid():  # 验证数据是否合法
         url = "".join([reverse('djManage'), "/article"])
         newTitle = form.cleaned_data['title']
         newBody = form.cleaned_data['body']
         if form.cleaned_data['abstract'] is None:
             newAbstract = newBody[:200]
         else:
             newAbstract = form.cleaned_data['abstract']
         newAbstract.replace('\s', '')
         newArticle = article(title=newTitle,
                              body=newBody,
                              abstract=newAbstract)
         print newArticle.body
         newArticle.save()
         return HttpResponseRedirect(url)