简体   繁体   English

在网站上运行 Python 脚本(在后台)

[英]Running a Python Script on a Website (in the background)

Firstly, apologies for the very basic question.首先,对非常基本的问题表示歉意。 I have looked into other answers but they haven't quite answered what I'm after.我已经查看了其他答案,但他们还没有完全回答我所追求的。 I'm confident designing a site in HTML/CSS and have very very basic knowledge of Python.我有信心用 HTML/CSS 设计一个网站,并且对 Python 有非常非常基本的了解。

I want to run a very basic Python script on my website.我想在我的网站上运行一个非常基本的 Python 脚本。 It analyses tweets about a specific topic, and then posts a sentiment analysis score.它分析有关特定主题的推文,然后发布情绪分析分数。 I want it to run this sentiment analysis every hour and cache the score.我希望它每小时运行一次情绪分析并缓存分数。

I have a working Python script which does this in Jupyter Notebook.我有一个可用的 Python 脚本,它在 Jupyter Notebook 中执行此操作。 Could you give me an overview of how I would make this script function online and cache the results?您能否概述一下如何使该脚本在线运行并缓存结果? I've read into using Python web frameworks, but from my limited understanding, they seem like overkill?我已经阅读过使用 Python Web 框架,但从我有限的理解来看,它们似乎有点矫枉过正?

Thank you for your help!感谢您的帮助!

Could you give me an overview of how I would make this script function online你能给我一个关于如何使这个脚本在线运行的概述吗?

The key thing would be to uncouple the two parts of your system:关键是要解耦系统的两个部分:

  • Producing the data生产数据
  • Showing it in a website.在网站上展示它。

So the first thing to do is have your sentiment-analysis script push its value to a database.因此,首先要做的是让您的情绪分析脚本将其值推送到数据库。 The database could be something as simple as a csv file, or it could be a key/value store, or something like MySQL or CouchDB (or hundreds of other choices).数据库可以是像 csv 文件一样简单的东西,也可以是键/值存储,或者像 MySQL 或 CouchDB(或数百种其他选择)之类的东西。

Over on the website you have to make a decision between:在网站上,您必须在以下各项之间做出决定:

  • Server-side服务器端
  • Client-side客户端

If the former, you could program in Python if that is what you are most familiar with.如果是前者,你可以用 Python 编程,如果那是你最熟悉的。 Whatever language/framework combination you go for, there will an example tutorial of how to read a value from a database and display it: it is just about the most fundamental thing.无论您选择哪种语言/框架组合,都会有一个示例教程,说明如何从数据库中读取值并显示它:这几乎是最基本的事情。

If client-side you will usually be programming in JavaScript.如果是客户端,您通常会使用 JavaScript 进行编程。 Again you need to choose a framework, but again you should easily be able to find a tutorial to follow.同样,您需要选择一个框架,但您应该能够轻松找到要遵循的教程。

(Unless you have a good reason to prefer server-side, such as familiarity with an existing framework, or security issues with accessing your database, I'd go with a client-side approach.) (除非您有充分的理由更喜欢服务器端,例如熟悉现有框架或访问数据库的安全问题,否则我会采用客户端方法。)

I've read into using Python web frameworks... overkill?我已经阅读了使用 Python 网络框架......矫枉过正?

Yes and no.是和否。 You are going to need some kind of database, and some kind of framework.您将需要某种数据库和某种框架。 It would be good to understand the basics of web security, too.了解网络安全的基础知识也会很好。 If the sentiment analysis is your major goal, all that is going to be a distraction, and it might be better to find a friend who already knows web programming to work with.如果情感分析是您的主要目标,那么所有这些都会让人分心,最好找一个已经知道网络编程的朋友一​​起工作。 Or just find a tutorial that is very close to what you want to do, and adapt that.或者只是找到一个与您想要做的事情非常接近的教程,然后进行调整。

(PS I was going to flag your question as "too broad", but you did ask for an overview, so I hope this helps.) (PS 我打算将您的问题标记为“太宽泛”,但您确实要求概述,所以我希望这会有所帮助。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM