我想在 Spring Boot 应用程序中订阅多个 Google Cloud PubSub 项目。阅读如何在一个 Spring Boot 应用程序中使用 Spring Cloud 连接/配置两个 pubsub gcp 项目中的相关问题后?,如何将 Spring Cloud GCP 用于多个 google 项目和https://github.com/spring-cloud/spring-cloud-gcp/issues/1639我尝试如下。但是,由于没有适当的文档或示例代码,我不清楚如何实现这一点。我收到以下给定的错误,这似乎是由于未加载凭据而引起的。
发布订阅配置
已评论第二个 PubSub 项目的配置。
package com.dialog.chatboard.config;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.gcp.pubsub.core.PubSubTemplate;
import org.springframework.cloud.gcp.pubsub.core.subscriber.PubSubSubscriberTemplate;
import org.springframework.cloud.gcp.pubsub.integration.inbound.PubSubInboundChannelAdapter;
import org.springframework.cloud.gcp.pubsub.support.DefaultSubscriberFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.messaging.MessageChannel;
@Configuration
public class PubSubConfig {
DefaultSubscriberFactory genieFactory = new DefaultSubscriberFactory(() -> "XXXXX-projectId-01");
PubSubSubscriberTemplate …Run Code Online (Sandbox Code Playgroud) java configuration spring-boot google-cloud-pubsub spring-cloud-gcp
我正在使用 MEAN Stack 和猫鼬。使用护照进行身份验证。我想获取当前登录的用户并显示他的详细信息。例如,如果我已登录并转到个人资料页面,我想获取我的详细信息。互联网上只有很少的资源。
Login.js(护照和路线在这里)
var express = require('express');
var router = express.Router();
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var User = require('../models/user');
var ConnectRoles = require('connect-roles');
router.get('/', function(req, res, next) {
res.render('Login', { title: 'Login' });
});
passport.serializeUser(function(user, done) {
done(null, user._id);
});
passport.deserializeUser(function(id, done) {
User.findById(id, function(err, user) {
done(err, user);
});
});
passport.use("/", new LocalStrategy(
function(username, password, done) {
User.findOne({ username: username }, function(err, user) {
if (err) { return done(err); }
if (!user) { …Run Code Online (Sandbox Code Playgroud) 我在https://test.pypi.org上传了一个简单的 python 包。当我用 pip 下载它并尝试 yo run 我得到FileNotFoundError: [Errno 2] File b'data/spam_collection.csv' does not exist: b'data/spam_collection.csv'. 早些时候我在打包时上传 csv 文件时遇到问题。请参阅我在无法将 csv 文件上传到 test.pypi.org 中的问题。现在,在使用 pip 安装软件包后,我运行pip show -f bigramspamclassifier. 我得到了列出的 csv 文件。因此,我相信该文件已上传。我认为问题在于读取包中我的 python 文件中的文件。SpamClassifier.py 中 csv 文件的路径应该是什么?
pip show -f bigramspamclassifier
Version: 0.0.3
Summary: A bigram approach for classifying Spam and Ham messages
Home-page: ######
Author: #####
Author-email: #######
Location: /home/kabilesh/PycharmProjects/TestPypl3/venv/lib/python3.6/site-packages
Requires: nltk, pandas
Required-by:
Files:
bigramspamclassifier-0.0.3.dist-info/INSTALLER
bigramspamclassifier-0.0.3.dist-info/LICENSE
bigramspamclassifier-0.0.3.dist-info/METADATA
bigramspamclassifier-0.0.3.dist-info/RECORD
bigramspamclassifier-0.0.3.dist-info/WHEEL
bigramspamclassifier-0.0.3.dist-info/top_level.txt
bigramspamclassifier/SpamClassifier.py …Run Code Online (Sandbox Code Playgroud) 我使用以下代码通过 Tweepy 从用户时间线下载推文。但是,这也会返回推文,包括用户的转发和回复。我只想在用户自己的时间线中发布推文。我怎样才能过滤这个结果?
原因是我想收集化妆品公司发布的有关其产品的推文。他们时间线中的推文给了我这个。不过,回复和转发看起来就像是常规对话,不谈论产品。我想把这些过滤掉。
import tweepy
import csv
import time
# Twitter API credentials
consumer_key = "xxxxxxx"
consumer_secret = "xxxxx"
access_key = "xxxxxxx"
access_secret = "xxxx"
def get_all_tweets(screen_name):
# Twitter only allows access to a users most recent 3240 tweets with this method
# authorize twitter, initialize tweepy
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
# initialize a list to hold all the tweepy Tweets
alltweets = []
# make initial request for most recent tweets (200 is …Run Code Online (Sandbox Code Playgroud) 我正在使用 matplotlib.pyplot 来可视化我的数据。在 pandas 中,我有“hour”和“hour”列'favourite_count'。hour 的值范围为 0 到 24。favourite_count是连续变量。我想要的是绘制一个条形图,直观地显示favourite_count每小时的平均值。目前我正在绘制如下基本图表。在 y 轴上,绘制了每小时的总和/最大值favourite_count(我不确定是哪一个)。如何绘制可视化小时与时间的图表average_favorite_count_for_hour
plt.bar(result['hour'], result['favourite_count'])
plt.xlabel('hour')
plt.ylabel('favourite_count')
plt.title('hour vs popularity', y=1.1)
plt.grid()
plt.show()
Run Code Online (Sandbox Code Playgroud) 经过一番搜索,我找到了一种从给定用户下载最近推文的方法。现在我想得到每条推文的回复。我知道 Twitter API 不提供端点来获取推文的回复,除非我们有一个高级帐户。但是我可以在互联网上找到一些解决方法。我找到了一种方法,可以使用从特定用户获取对特定推文的推文回复来获取很少的推文及其回复。下面也给出了这个代码。
如何修改我的代码 (getData.py) 以保存每条推文的回复以及 csv 中的推文?
我将用户的推文下载为 csv (getData.py) 的代码
import tweepy
import csv
# Twitter API credentials
consumer_key = "###########"
consumer_secret = "################"
access_key = "#################"
access_secret = "#####################"
def get_all_tweets(screen_name):
# Twitter only allows access to a users most recent 3240 tweets with this method
# authorize twitter, initialize tweepy
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
# initialize a list to hold all the tweepy Tweets
alltweets = []
# …Run Code Online (Sandbox Code Playgroud) 我正在使用 tweepy api 收集推文,我想要推文的全文。参考https://github.com/tweepy/tweepy/issues/974中的示例,tweepy Streaming API:全文和Tweepy 截断状态我使用extended_mode 进行了尝试。但是我收到一条错误消息,说AttributeError: 'Status' object has no attribute 'full_text'。
从上面的例子我知道如果推文不超过 140 个字符,那么必须像往常一样获取文本。但是,这些示例是针对 StreamListener 的,我没有使用 StreamListener。如何使用tweepy Streaming API 中的 try catch 块:全文并解决我得到的错误并获取推文的全文?我应该如何修改我下面的代码?
获取数据文件
import tweepy
import csv
# Twitter API credentials
consumer_key = ""
consumer_secret = ""
access_key = ""
access_secret = ""
def get_all_tweets(screen_name):
# Twitter only allows access to a users most recent 3240 tweets with this method
# authorize twitter, initialize …Run Code Online (Sandbox Code Playgroud) 我试图使用System.Speech该类在ASP.NET mvc应用程序中生成语音。
[HttpPost]
public ActionResult TTS(string text)
{
SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer();
speechSynthesizer.Speak(text);
return View();
}
Run Code Online (Sandbox Code Playgroud)
但是它给出了以下错误。
System.InvalidOperationException: 'An asynchronous operation cannot be
Started at this time. Asynchronous operations may only be started within an
asynchronous handler or module or during certain events in the Page lifecycle.
If this exception occurred while executing a Page, ensure that the Page is
marked <%@ Page Async="true" %>.
This exception may also indicate an attempt to call an "async void" …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 python 中解码 utf-8 编码文本。数据被加载到 pandas 数据帧中,然后进行解码。这会产生错误:AttributeError: 'Series' object has no attribute 'decode'。如何正确解码 pandas 列中的文本?
>> preparedData.head(5).to_dict( )
{'id': {0: 1042616899408945154, 1: 1042592536769044487, 2: 1042587702040903680, 3: 1042587263643930626, 4: 1042586780292276230}, 'date': {0: '2018-09-20', 1: '2018-09-20', 2: '2018-09-20', 3: '2018-09-20', 4: '2018-09-20'}, 'time': {0: '03:30:14', 1: '01:53:25', 2: '01:34:13', 3: '01:32:28', 4: '01:30:33'}, 'text': {0: "b'\\xf0\\x9f\\x8c\\xb9 are red, violets are blue, if you want to buy us \\xf0\\x9f\\x92\\x90, here is a CLUE \\xf0\\x9f\\x98\\x89 Our #flowerpowered eye & cheek palette is …Run Code Online (Sandbox Code Playgroud) 我有一串ndarray。我想将其转换回ndarray。我试过了 newval = np.fromstring(val, dtype=float)。但是它给ValueError: string size must be a multiple of element size
我也试过了newval = ast.literal_eval(val)。这给
File "<unknown>", line 1
[-1.45181984e-01 1.51671678e-01 1.59053639e-01 -1.02861412e-01
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
ndarray的字符串
'[-1.45181984e-01 1.51671678e-01 1.59053639e-01 -1.02861412e-01
-9.70948339e-02 -1.75551832e-01 -7.24434480e-02 1.19182713e-01
-4.54084426e-02 -9.23779532e-02 8.87222588e-02 1.05331177e-02
-1.31792471e-01 3.50326337e-02 -6.58577830e-02 1.02670217e+00
-5.29987812e-02 2.09167395e-02 -1.19845152e-01 2.30511073e-02
2.89404951e-02 4.17387672e-02 -2.08203331e-01 2.34342851e-02]'
Run Code Online (Sandbox Code Playgroud)
如何将其转换回ndarray?
我有一个如下所示的熊猫数据框。我想将所有文本转换为小写。我怎样才能在Python中做到这一点?
\n\n\n\n\n数据框样本
\n
[Nah I don't think he goes to usf, he lives around here though] \n\n[Even my brother is not like to speak with me., They treat me like aids patent.] \n\n[I HAVE A DATE ON SUNDAY WITH WILL!, !] \n\n[As per your request 'Melle Melle (Oru Minnaminunginte Nurungu Vettam)' has been set as your callertune for all Callers., Press *9 to copy your friends Callertune] \n\n[WINNER!!, As a valued network customer you have been selected …Run Code Online (Sandbox Code Playgroud) python ×8
tweepy ×3
pandas ×2
twitter ×2
asp.net-mvc ×1
async-await ×1
c# ×1
csv ×1
java ×1
matplotlib ×1
nlp ×1
node.js ×1
numpy ×1
packaging ×1
passport.js ×1
pypi ×1
spring-boot ×1