我正在尝试使用AngularJS在firebase上存储和检索我的数据.到目前为止,我已经构建了一个Ionic选项卡项目并创建了自定义控制器和自定义工厂.我知道在工厂中检索数据并通过控制器处理数据是一种惯例.但是,我不明白为什么我的下面的代码不起作用:
services.js
angular.module('starter.services', ['firebase'])
.factory('OtherFriends', ['$firebase', function ($firebase) {
var ref = new Firebase("https://example1234.firebaseio.com/friendlist");
var sync = $firebase(ref);
var otherfriends = sync.$asArray();
return {
all: function() {
return otherfriends;
},
get: function(friendId) {
// Simple index lookup
return otherfriends[friendId];
}
}
}])
Run Code Online (Sandbox Code Playgroud)
controllers.js
angular.module('starter.controllers', [])
// OTHER CONTROLLERS
.controller('OtherFriendsCtrl', function($scope, OtherFriends) {
$scope.otherfriends = OtherFriends.all();
})
Run Code Online (Sandbox Code Playgroud)
制表otherfriends.html
<ion-view title="OtherFriends">
<ion-content>
<ion-list>
<ion-item ng-repeat="otherfriend in otherfriends" type="item-text-wrap" href="#/tab/otherfriend/{{otherfriend.id}}">
{{otherfriend.name}}
</ion-item>
</ion-list>
</ion-content>
</ion-view>
Run Code Online (Sandbox Code Playgroud)
app.js
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'firebase']) …Run Code Online (Sandbox Code Playgroud) 我上传了一个 AWS Lambda 函数,其中 lambda_handler 如下所示:
import json
def lambda_handler(event, context):
print(event)
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!'),
'event': event
}
Run Code Online (Sandbox Code Playgroud)
问题一:退货 event
当我使用 Lambda 管理控制台测试它时,我可以创建一个带有参数的测试事件,这些参数也返回完全相同的格式并且一切正常:
{
"key1": "value1",
"key2": "value2",
"key3": "value3"
}
Run Code Online (Sandbox Code Playgroud)
但是,当我使用 Postman 时,我得到了完全不同的东西,这又回到了我的身边:
{
"message": "Internal server error"
}
Run Code Online (Sandbox Code Playgroud)
我怀疑是因为它event看起来更像:
{'resource': '/hello', 'path': '/hello', 'httpMethod': 'GET', 'headers': {'Accept': '*/*', ... etc
Run Code Online (Sandbox Code Playgroud)
问题二:在body中添加json参数会报错
当我尝试在 Postman 中添加 body > raw > JSON(application/JSON) 上面的键时,我收到错误消息:
ERROR: The request could not be satisfied
Run Code Online (Sandbox Code Playgroud)
问题
我有两个问题:
我正在尝试读取 Python 内存中 SFTP 上的 CSV 文件。我尝试了以下方法,它适用于 FTP 连接,但不适用于 SFTP。
例如,我想复制:
df = pd.read_csv(...)
Run Code Online (Sandbox Code Playgroud)
但不首先将其存储在本地(原因是因为我想将其作为云函数运行,然后我不希望本地文件在我的缓存中)。
我怎样才能做到不同呢?
def read_file_sftp_local_memory(sftp, path, filename):
flo = BytesIO()
path_query = "".join(['RETR ', path, '/', filename])
sftp.retrbinary(path_query, flo.write)
flo.seek(0)
return flo
Run Code Online (Sandbox Code Playgroud)
我还尝试了以下方法:
def read_file_csv(sftp, path, filename):
# Download
sftp.get("/".join( os.path.join(path, filename) ), filename)
# Read
df = pd.read_csv(filename)
# Delete
os.remove(filename)
# Return
return df
Run Code Online (Sandbox Code Playgroud)
但返回这个错误:
df = pd.read_csv(...)
Run Code Online (Sandbox Code Playgroud) 我想每 x 分钟运行一次 gsutil 命令作为云函数。我尝试了以下方法:
# main.py
import os
def sync():
line = "gsutil -m rsync -r gs://some_bucket/folder gs://other_bucket/other_folder"
os.system(line)
Run Code Online (Sandbox Code Playgroud)
当云函数被触发时,该行的执行不起作用(即文件没有从一个存储桶复制到另一个存储桶)。但是,当我在 Pycharm 本地或使用 cmd 本地运行它时,它确实工作正常。与云功能有什么区别?
python google-cloud-storage gsutil google-cloud-platform google-cloud-functions
我想用原始图像创建拼图图像,这意味着将图像切割成9个(3x3)然后随机洗牌并存储为新图像.有谁知道哪种方法是最好的,以及如何实现它?或许与CamanJS?有没有人有示例代码?
运行以下Python Panda代码时:
xl = pd.ExcelFile(dataFileUrl)
sheets = xl.sheet_names
data = xl.parse(sheets[0])
colheaders = list(data)
Run Code Online (Sandbox Code Playgroud)
我收到ValueError:
Must explicitly set engine if not passing in buffer or path for io
Run Code Online (Sandbox Code Playgroud)
毫无疑问,该文件肯定是excel文件。
怎么了?
我有以下pandas DataFrame专栏dfA['TradeDate']:
0 20100329.0
1 20100328.0
2 20100329.0
...
Run Code Online (Sandbox Code Playgroud)
我希望将它转换为日期时间.
基于SO上的另一个步骤,我首先将其转换为字符串,然后应用该strptime函数.
dfA['TradeDate'] = datetime.datetime.strptime( dfA['TradeDate'].astype('int').to_string() ,'%Y%m%d')
Run Code Online (Sandbox Code Playgroud)
但是,这会返回我的格式不正确的错误(ValueError).
我发现的一个问题是列不是正确的字符串,而是对象.
当我尝试:
dfA['TradeDate'] = datetime.datetime.strptime( dfA['TradeDate'].astype(int).astype(str),'%Y%m%d')
Run Code Online (Sandbox Code Playgroud)
它返回:必须是Str而不是Series.
我无法让 Firebase Storage 使用自定义规则和自定义声明。
在我的 Python 管理面板中,我执行以下操作来创建用户并分配声明 client_id:
# Standard Auth
import firebase_admin
from firebase_admin import db, storage, auth
cred = firebase_admin.credentials.Certificate('path_to_cert_json')
app = firebase_admin.initialize_app(cred, 'config')
bucket = storage.bucket(app=app)
# Create User
auth.create_user(email=email)
# Create custom claims
auth.set_custom_user_claims(uid, {'client_id': client_id})
Run Code Online (Sandbox Code Playgroud)
然后,对于 Firebase 规则,我尝试仅当文件位于具有 client_id 的子文件夹中时才允许用户读取(或下载)文件:
存储上的文件结构:
/{environment}/{client_id}/other_folders_and_files
Run Code Online (Sandbox Code Playgroud)
我设置了以下存储规则:
service firebase.storage {
match /b/{bucket}/o {
match /{environment}/{client_id}/{allPaths=**} {
allow read: if request.auth.token.client_id == client_id
}
}
}
Run Code Online (Sandbox Code Playgroud)
但这给了我一个错误,即权限被拒绝。
我究竟做错了什么?
笔记:
python firebase firebase-security firebase-authentication firebase-storage
我正在尝试使用 Google Cloud Functions 发送多个抓取请求。但是,我似乎收到了错误ReactorNotRestartable。从 StackOverflow 上的其他帖子(例如这篇文章)中,我了解到这是因为无法重新启动反应器,特别是在执行循环时。
解决这个问题的方法是把start()for循环放在外面。但是,对于云功能,这是不可能的,因为每个请求在技术上都应该是独立的。
是否以CrawlerProcess某种方式使用 Cloud Functions 进行缓存?如果是这样,我们如何消除这种行为。
例如,我尝试将导入和初始化过程放在函数内部而不是外部,以防止缓存导入,但这不起作用:
# main.py
def run_single_crawl(data, context):
from scrapy.crawler import CrawlerProcess
process = CrawlerProcess()
process.crawl(MySpider)
process.start()
Run Code Online (Sandbox Code Playgroud) 我有一个文件,它是gulp的sass设置_variables.scss的一部分。
在此文件中,我能够导入 Google 字体,如下所示:
$font: "https://fonts.googleapis.com/css?family=Nunito:300,400,600,700" !default;
$font-family-custom-sans-serif: "Nunito", sans-serif !default;
$font-family-base: $font-family-custom-sans-serif !default;
Run Code Online (Sandbox Code Playgroud)
我现在尝试用文件中的自定义导入替换此字体.woff2。我尝试了以下方法,但这似乎不起作用:
@font-face {
font-family: 'Gellix';
src: url("../../assets/img/brand/Gellix-Bold.woff2") format('woff2'),
url("../../assets/img/brand/Gellix-Regular.woff2") format('woff2')
}
$font: "Gellix", sans-serif !default;
$font-family-custom-sans-serif: "Gellix", sans-serif !default;
$font-family-base: $font-family-custom-sans-serif !default;
Run Code Online (Sandbox Code Playgroud) python ×7
pandas ×3
firebase ×2
angularjs ×1
aws-lambda ×1
camanjs ×1
css ×1
dataframe ×1
datetime ×1
font-face ×1
fonts ×1
gsutil ×1
gulp ×1
html5-canvas ×1
http ×1
javascript ×1
paramiko ×1
postman ×1
python-3.x ×1
sass ×1
scrapy ×1
sftp ×1
valueerror ×1