小编wyx*_*wyx的帖子

Firebase(FCM)如何获取令牌

这是我第一次使用FCM.

我从firebase/quickstart-android下载了一个示例,我安装了FCM Quickstart.But我甚至无法从日志中获取任何令牌,甚至点击应用程序中的LOG TOKEN按钮.

然后我尝试使用Firebase控制台发送消息并设置为我的应用程序包名称.我收到任何传入消息.

我想知道可以使用FCM吗?GCM一切正常.

解:

因为我不是Android开发人员,只是一个后端开发人员.所以我需要一些时间来解决它.在我看来,示例应用程序中存在一些错误.

在此输入图像描述

码:

RegistrationIntentService.java

public class RegistrationIntentService extends IntentService {

    private static final String TAG = "RegIntentService";


    public RegistrationIntentService() {
        super(TAG);
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        String token = FirebaseInstanceId.getInstance().getToken();
        Log.i(TAG, "FCM Registration Token: " + token);
    }
}
Run Code Online (Sandbox Code Playgroud)

MyFirebaseInstanceIDService.java

public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {

    private static final String TAG = "MyFirebaseIIDService";

    /**
     * Called if InstanceID token is updated. This may occur if the security of …
Run Code Online (Sandbox Code Playgroud)

android firebase firebase-cloud-messaging

76
推荐指数
14
解决办法
17万
查看次数

Python3.5中的__metaclass__

在Python2.7这个代码可以很好地工作,__getattr__MetaTable 运行.但是在Python 3.5中它不起作用.

class MetaTable(type):
    def __getattr__(cls, key):
        temp = key.split("__")
        name = temp[0]
        alias = None

        if len(temp) > 1:
            alias = temp[1]

        return cls(name, alias)


class Table(object):
    __metaclass__ = MetaTable

    def __init__(self, name, alias=None):
        self._name = name
        self._alias = alias


d = Table
d.student__s
Run Code Online (Sandbox Code Playgroud)

但是在Python 3.5中我得到了一个属性错误:

Traceback (most recent call last):
  File "/Users/wyx/project/python3/sql/dd.py", line 31, in <module>
    d.student__s
AttributeError: type object 'Table' has no attribute 'student__s'
Run Code Online (Sandbox Code Playgroud)

python metaclass

12
推荐指数
1
解决办法
8738
查看次数

在Mac上将硒与chromedriver一起使用

我想在Mac上将硒与chromedriver一起使用,但遇到了一些麻烦。

  1. 我从下载chromedriver ChromeDriver-WebDriver for Chrome
  2. 但我不想将其放入PATH。

在此处输入图片说明

import os

from selenium import webdriver

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
DRIVER_BIN = os.path.join(PROJECT_ROOT, "bin/chromedriver_for_mac")
print DRIVER_BIN
browser = webdriver.Chrome(DRIVER_BIN)
browser.get('http://www.baidu.com/')
Run Code Online (Sandbox Code Playgroud)

但是我无法获得想要的结果。

Traceback (most recent call last):
  File "/Users/wyx/project/python-scraping/se/test.py", line 15, in <module>
    browser = webdriver.Chrome(DRIVER_BIN)
  File "/Users/wyx/project/python-scraping/.env/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
    self.service.start()
  File "/Users/wyx/project/python-scraping/.env/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 71, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver_for_mac' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of …
Run Code Online (Sandbox Code Playgroud)

python selenium

8
推荐指数
3
解决办法
2万
查看次数

如何使用Python 2.7在Mac上安装ctypes

(.env) ?  ~ easy_install ctypes
Searching for ctypes
Reading https://pypi.python.org/simple/ctypes/
No local packages or download links found for ctypes
error: Could not find suitable distribution for Requirement.parse('ctypes')


(.env) ?  ~ pip install ctypes
Collecting ctypes
  Could not find a version that satisfies the requirement ctypes (from versions: )
No matching distribution found for ctypes
Run Code Online (Sandbox Code Playgroud)

我使用easy_install或pip来安装ctypes,但它们都失败了.

所以我下载ctypes-1.0.2-AMD64.zip进行安装

(.env) ?  ctypes-1.0.2 sudo python setup.py build
Password:
running build
running build_py
running build_ext
Configuring static FFI library:
cd build/temp.macosx-10.11-intel-2.7/libffi && env CFLAGS='' '/Users/wyx/Downloads/ctypes-1.0.2/source/libffi/configure' …
Run Code Online (Sandbox Code Playgroud)

python macos python-2.7

3
推荐指数
1
解决办法
5799
查看次数

如何在Python中停止os.system()?

我想在 12 秒后停止 cmd 命令。怎么阻止呢?我的程序不起作用。

import multiprocessing
import os
import time


def process():
    os.system('ffmpeg -i rtsp://218.204.223.237:554/live/1/66251FC11353191F/e7ooqwcfbqjoo80j.sdp -c copy dump.mp4')


def stop():
    time.sleep(12)


if __name__ == '__main__':
    p = multiprocessing.Process(target=process, args=())
    s = multiprocessing.Process(target=stop, args=())
    p.start()
    s.start()
    s.join()
    p.terminate()
Run Code Online (Sandbox Code Playgroud)

我按照佩德罗的建议@Pedro Lobito更改了我的程序,但它仍然不起作用。

import shlex

import subprocess
import time

command_line = 'ffmpeg -i rtsp://218.204.223.237:554/live/1/66251FC11353191F/e7ooqwcfbqjoo80j.sdp -c copy dump.mp4'

proc = subprocess.Popen(shlex.split(command_line), shell=True)
print '1' * 50
time.sleep(2)  # <-- sleep for 12''
print '2' * 50
proc.terminate()  # <-- terminate the process
print '3' …
Run Code Online (Sandbox Code Playgroud)

python ffmpeg

1
推荐指数
1
解决办法
1万
查看次数

如何在clickhouse中更改分区

版本 18.16.1

CREATE TABLE traffic (
    `date` Date,
    ...
) ENGINE = MergeTree(date, (end_time), 8192);
Run Code Online (Sandbox Code Playgroud)

我想在PARTITION BY toYYYYMMDD(date)没有删除表的情况下更改如何执行此操作。

clickhouse

1
推荐指数
1
解决办法
1400
查看次数