English 中文(简体)
交换选票问题
原标题:pystackexchange polling issue

因此,我很新到晚上,我今天有一种想法,即制作一部对我的背书进行 poll击的文字,并在作改动时发出电子邮件,作为文本寄给我的电话。

电子邮件部分工作,但出于某种原因,我可以拿到投票权,因此我决定,我看看看你是否想在座标。

我的守则如下:

import sys
from stackauth import StackAuth
from stackexchange import Site, StackOverflow
import smtplib

from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email import Encoders
import os

import time

gmail_user = "email@gmail.com"
gmail_pwd = "password"

def mail(to, subject, text):
   msg = MIMEMultipart()

   msg[ From ] = gmail_user
   msg[ To ] = to
   msg[ Subject ] = subject

   msg.attach(MIMEText(text))

   mailServer = smtplib.SMTP("smtp.gmail.com", 587)
   mailServer.ehlo()
   mailServer.starttls()
   mailServer.ehlo()
   mailServer.login(gmail_user, gmail_pwd)
   mailServer.sendmail(gmail_user, to, msg.as_string())
   # Should be mailServer.quit(), but that crashes...
   mailServer.close()

old_rep = None

while True:

    user_id = 731221 if len(sys.argv) < 2 else int(sys.argv[1])
    print  StackOverflow user %d s accounts:  % user_id

    stack_auth = StackAuth()
    so = Site(StackOverflow)
        accounts = stack_auth.associated(so, user_id)
    REP =  accounts[3].reputation
    print REP
        if REP != old_rep:
        old_rep = REP
                mail("email@email.com","REP",str(REP))
    time.sleep(10)

Currently if you print REP it is right at first, but doesnt update if my rep changes. Ideally it would. Any help is greatly appreciated. Thanks in advance.

问题回答

This is a simplified example that will loop properly:

import time
from stackauth import StackAuth
from stackexchange import Site, StackOverflow

rep = None
while True:
    stack_auth = StackAuth()
    so = Site(StackOverflow)
    accounts = stack_auth.associated(so, 641766) # using my id
    so_acct = filter(lambda x: x.on_site.api_endpoint.endswith( api.stackoverflow.com ), accounts)[0] # filtering my accounts so I only check rep on stackoverflow
    if rep != so_acct.reputation:
        rep = so_acct.reputation
        print rep
        # send e-mail
    time.sleep(30)

我增加了一行,以过滤账户,只检查贵重物品在适当地点。 你们正在使用该指数,如果该指数是稳定的,我就没有想法,我是不是这样。 每10秒(如原例)的投票率可能微不足道,可能比每5分钟更合理? 你们真的需要一分钟才能更新你们的回忆? 考虑仅写这本书,每5、10、15分钟。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签