小编Mit*_*ril的帖子

jekyll插件在github上不起作用

我想通过改变在导航中栏的页面顺序jekyll-plugins / weighted_pages.rb这里

这个插件在我的本地主机上很好,但是在github上也很好。
我发现github主机上的导航栏为空,看来此插件不起作用。
我怎么解决这个问题?

weighted_pages.rb在下面复制代码:

# Generates a copy of site.pages as site.weighted_pages
# with pages sorted by weight attribute. Pages with no
# weight specified are placed after the pages with specified weight.

module Jekyll

  class WeightedPagesGenerator < Generator
    safe true

    def generate(site)
      site.config['weighted_pages'] = site.pages.sort_by { |a| 
        a.data['weight'] ? a.data['weight'] : site.pages.length }
    end

  end

end
Run Code Online (Sandbox Code Playgroud)

weight属性添加到您的首要问题,pages (like weight: 1)并在循环中使用site.weighted_pages而不是site.pages

ruby github jekyll

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

Django模型查询使用join

我想使查询工作如下sql:

sql_str = '''
    select * from luckydraw_winner W
    inner join luckydraw_prizeverificationcodesmslog L on W.id =L.winner_id
    where W.lucky_draw_id = %s
    limit 10
'''
Run Code Online (Sandbox Code Playgroud)

楷模:

class Winner(models.Model):
    lucky_draw = models.ForeignKey(LuckyDraw)
    participation = models.ForeignKey(Participation)
    prize = models.ForeignKey(Prize)
    mobile_number = models.CharField(max_length=15, null=True, default = None)

class PrizeVerificationCodeSMSLog(models.Model):
    winner = models.ForeignKey(Winner)
    mobile_number = models.CharField(max_length=15, db_index=True)
    created_on = models.DateTimeField(auto_now_add=True)
Run Code Online (Sandbox Code Playgroud)

因为 mobile_number并不总是填写Winner模型,我想要的是拥有手机号码或获得短信的赢家.所以必须加入PrizeVerificationCodeSMSLog以实现我的目的.
只有赢家很简单:

winners = models.Winner.objects.filter(lucky_draw_id=id).order_by('-created_on')[:10]
Run Code Online (Sandbox Code Playgroud)

但我不知道可以添加什么过滤器来加入PrizeVerificationCodeSMSLog.


我终于明白了如何在django中检索我想要的数据.

如果您想让A另一个B具有外键的模型限制模型A,请不要尝试使用filter().因为A不知道 …

python django django-orm django-queryset

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

lxml无法解析xml(其他编码是否为utf-8)[python]

我的代码:

import re
import requests
from lxml import etree

url = 'http://weixin.sogou.com/gzhjs?openid=oIWsFt__d2wSBKMfQtkFfeVq_u8I&ext=2JjmXOu9jMsFW8Sh4E_XmC0DOkcPpGX18Zm8qPG7F0L5ffrupfFtkDqSOm47Bv9U'

r = requests.get(url)

items = r.json()['items']
Run Code Online (Sandbox Code Playgroud)
  1. 没有编码('utf-8'):

etree.fromstring(items[0]) 输出:

ValueError                                
Traceback (most recent call last)
<ipython-input-69-cb8697498318> in <module>()
----> 1 etree.fromstring(items[0])

lxml.etree.pyx in lxml.etree.fromstring (src\lxml\lxml.etree.c:68121)()

parser.pxi in lxml.etree._parseMemoryDocument (src\lxml\lxml.etree.c:102435)()

ValueError: Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments without declaration.
Run Code Online (Sandbox Code Playgroud)
  1. with encode('utf-8'):

etree.fromstring(items[0].encode('utf-8')) 输出:

  File "<string>", line unknown
XMLSyntaxError: CData section not finished
?????????:???I??, line 1, column 281
Run Code Online (Sandbox Code Playgroud)

不知道解析这个xml ..

python xml lxml xml-parsing python-2.7

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

用于生产者和工作人员(python)的任何本地任务队列(可能是磁盘队列或内存队列?)?

我使用过很多分发任务包,例如celery,,python-rq它们都依赖于外部服务,例如redisrabbit-mq等等。

但是,通常我不需要queue service,换句话说,不想redis在我的vps上安装或其他非python服务。(也是为了简化环境)

producer我应该说,拆分和worker不同的进程(两个代码文件)是很好的。使用multiprocessing.Queue需要将所有内容放入一个文件中,并且需要编写大量附加代码来捕获ctrl+c以处理exit并保存当前排队的任务。celery使用,不会发生这种情况python-rq,尽管停止工作人员和生产者,但任务仍然保存在队列中。

我想使用本地队列(可以通过pip install xxx),例如磁盘队列。经过一番搜索,只找到了queuelib(持久(基于磁盘)队列的集合),但遗憾的是它不支持多进程访问。

python queue multithreading task

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

如何使用ObjectListView显示包含当前行索引的列?

我有以下课程:

public class people
{
    public string name { get; set; }
    public string hobby { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我想显示一个这样的列表:

no | name | hobby
-----------------------
01 | kim  | tv
02 | kate | pc
03 | kim  | tv
04 | kate | pc
Run Code Online (Sandbox Code Playgroud)

我知道要实现这一目标的唯一方法是将人们的阶级转变为

public class people
{
    public string no{ get; set; }
    public string name { get; set; }
    public string hobby { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

并循环List<people>设置每个no属性。

有没有更好的方法来添加索引号列?

.net c# winforms objectlistview

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

python threading具有线程安全性的队列生产者 - 消费者

我正在使用线程和队列来获取URL并存储到数据库.
我只想要一个线程来做存储工作.
所以我写代码如下:

import threading
import time

import Queue

site_count = 10

fetch_thread_count = 2

site_queue = Queue.Queue()
proxy_array=[]        


class FetchThread(threading.Thread):
    def __init__(self,site_queue,proxy_array):
        threading.Thread.__init__(self)
        self.site_queue = site_queue
        self.proxy_array = proxy_array
    def run(self):
        while True:
            index = self.site_queue.get()
            self.get_proxy_one_website(index)
            self.site_queue.task_done()
    def get_proxy_one_website(self,index):
        print '{0} fetched site :{1}\n'.format(self.name,index)
        self.proxy_array.append(index)


def save():
    while True:
        if site_queue.qsize() > 0:
            if len(proxy_array) > 10:
                print 'save :{0}  to database\n'.format(proxy_array.pop())

            else:
                time.sleep(1)
        elif len(proxy_array) > 0:
            print 'save :{0} to database\n'.format(proxy_array.pop())

        elif len(proxy_array) == 0:
            print …
Run Code Online (Sandbox Code Playgroud)

python queue multithreading

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

南迁移错误,InnoDB:ROW_FORMAT = DYNAMIC需要innodb_file_format>羚羊

我迁移数据发生错误.
我试着在下面运行原始的SQL:
ALTER TABLE wxwall_participationADD COLUMN eventINT DEFAULT 0
ALTER TABLE wxwall_sceneADD COLUMN welcome_msgVARCHAR(400)NULL
它们工作得非常好,这让我很迷惑.我怎么能解决这个问题?

错误细节:

 - Migrating forwards to 0002_auto__add_field_participation_event__add_field_scene_welcome_msg.
 > wxwall:0002_auto__add_field_participation_event__add_field_scene_welcome_msg
 ! Error found during real run of migration! Aborting.

 ! Since you have a database that does not support running
 ! schema-altering statements in transactions, we have had
 ! to leave it in an interim state between migrations.

! You *might* be able to recover with:   - no dry run output for delete_foreign_key() …
Run Code Online (Sandbox Code Playgroud)

mysql django innodb django-south

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

使主管正确停止芹菜工人

我在使用芹菜时遇到了很多奇怪的事情。比如,我更新tasks.py,supervisorctl reload(重启),但是tasks错了。有些任务似乎消失了等等。
今天我发现,因为supervisorctl stop all不能阻止所有的芹菜工人。并且只有 kill -9 'pgrep python' 可以将它们全部杀死。

情况:

    root@ubuntu12:/data/www/article_fetcher# supervisorctl
    celery_beat                      RUNNING    pid 29597, uptime 0:52:18
    celery_worker1                   RUNNING    pid 29556, uptime 0:52:20
    celery_worker2                   RUNNING    pid 29570, uptime 0:52:19
    celery_worker3                   RUNNING    pid 29557, uptime 0:52:20
    celery_worker4                   RUNNING    pid 29586, uptime 0:52:18
    uwsgi                            RUNNING    pid 29604, uptime 0:52:18
    supervisor> stop all
    celery_beat: stopped
    celery_worker2: stopped
    celery_worker4: stopped
    celery_worker3: stopped
    uwsgi: stopped
    celery_worker1: stopped
    supervisor> status
    celery_beat                      STOPPED    Aug 04 11:05 AM
    celery_worker1                   STOPPED    Aug 04 …
Run Code Online (Sandbox Code Playgroud)

python celery-task supervisord django-celery django-supervisor

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

如何将 python gcc 绑定更改为 gcc 4.8 版本?

我想安装一个 auto-sklearn 包,它依赖于pyrfr.

\n\n

安装命令是curl https://raw.githubusercontent.com/automl/auto-sklearn/master/requirements.txt | xargs -n 1 -L 1 pip install.

\n\n

我的环境:ubuntu 12.04,python3.5-dev(在 virtualenv 中),安装了 gcc 4.8 和 g++ 4.8。

\n\n

我通过以下方式安装 gcc 和 g++:

\n\n
sudo apt-get install python-software-properties\nsudo add-apt-repository ppa:ubuntu-toolchain-r/test\nsudo apt-get update\n\nsudo apt-get install gcc-4.8\nsudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50\n
Run Code Online (Sandbox Code Playgroud)\n\n

默认 gcc 设置正确:

\n\n
\xe2\x9e\x9c  ~ gcc -v\nUsing built-in specs.\nCOLLECT_GCC=gcc\nCOLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper\nTarget: x86_64-linux-gnu\nConfigured with: ../src/configure -v --with-pkgversion=\'Ubuntu 4.8.1-2ubuntu1~12.04\' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls …
Run Code Online (Sandbox Code Playgroud)

c++ python linux ubuntu gcc

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

postgresql(aws redshift) 错误 1204 字符串长度超过 DDL 长度

我正在尝试将 csv 导入 aws redshift( postgresql 8.x) 。

数据流是:mysql -> s3 上的 parquet 文件 -> s3 上的 csv 文件 -> redshift。

表结构

mysql表sql:

create table orderitems
(
  id                         char(36) collate utf8_bin not null
    primary key,
  store_id                   char(36) collate utf8_bin not null,
  ref_type                   int                       not null,
  ref_id                     char(36) collate utf8_bin not null,
  store_product_id           char(36) collate utf8_bin not null,
  product_id                 char(36) collate utf8_bin not null,
  product_name               varchar(50)               null,
  main_image                 varchar(200)              null,
  price                      int                       not null,
  count                      int                       not null,
  logistics_type             int                       not …
Run Code Online (Sandbox Code Playgroud)

python postgresql import amazon-redshift

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