python flask服务器_使用python中的Flask运行web服务器

我使用cloud9ide并使用默认的Web服务器。但是代码不会启动服务器(web服务器返回:这里似乎没有运行任何应用程序!)。

我仔细检查了代码的每一个实例,但我在烧瓶方面很薄弱。烧瓶代码是分配代码的一部分。在

代码:

应用程序.py(应该会启动服务器)from flask import Flask, redirect, render_template, request, url_for

import sys, helpers

from analyzer import Analyzer

app = Flask(__name__)

@app.route("/")

def index():

return render_template("index.html")

@app.route("/search")

def search():

# validate screen_name

screen_name = request.args.get("screen_name", "")

if not screen_name:

return redirect(url_for("index"))

# get screen_name's tweets

tweets = helpers.get_user_timeline(screen_name)

# pass to analyze

analyzer = Analyzer("positive-words.txt", "negative-words.txt")

positive, negative, neutral = analyzer.analyze(tweets)

# generate chart

chart = helpers.chart(positive, negative, neutral)

# render results

return render_template("search.html", chart=chart, screen_name=screen_name)

在助手.py(所用方法应用程序.py)公司名称:

^{pr2}$

在分析器.py(所用方法应用程序.py)公司名称:# Tokenizing library

import nltk

class Analyzer():

# Defining template for the class with two arguments(file names are not hard coded)

def __init__(self, positives, negatives):

# Two dicts for - and + words

self.positives = {}

self.negatives = {}

# Method for reading files into dicts

def open_file (file_name, dictionary_name):

with open(file_name) as f:

# Loop to start with 35th line

for i in range(35):

next(f)

for line in f:

# Keys and values of a dict

dictionary_name[line.strip()] = line.strip()

# Calling methods

open_file(positives, self.positives)

open_file(negatives, self.negatives)

# Analyse tokens

def analyze(self, text):

# Access tools of nltk

tokenizer = nltk.tokenize.TweetTokenizer()

# Defining couning score variable

score_positive = 0

score_negative = 0

score_neutral = 0

# since the text is a list we itterate of the list element by element

for tweet in text:

tokens = tokenizer.tokenize(tweet)

# Checking each token

for token in tokens:

if token.lower() in self.positives:

score_positive += 1

elif token.lower() in self.negatives:

score_negative += 1

else:

score_neutral += 1

return score_positive, score_negative, score_neutral

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值