0

pygooglevoice を利用してメッセージを受信し、ID を使用してすぐに削除しようとしていますが、わかりdelete()ません。

ドキュメントは次のとおりです: http://sphinxdoc.github.com/pygooglevoice/ :

from googlevoice import Voice 
from googlevoice.util import input 
import sys, BeautifulSoup

voice = Voice()
voice.login()
voice.sms()

def sendTextMessage(phoneNumber,text):
    voice.send_sms(phoneNumber, text)
    return 0

def extractsms(htmlsms):
    """
    extractsms  --  extract SMS messages from BeautifulSoup tree of Google Voice SMS HTML.

    Output is a list of dictionaries, one per message.
    """
    msgitems = []                                       # accum message items here
    #   Extract all conversations by searching for a DIV with an ID at top level.
    tree = BeautifulSoup.BeautifulSoup(htmlsms)         # parse HTML into tree
    conversations = tree.findAll("div",attrs={"id" : True},recursive=False)
    for conversation in conversations :
        #   For each conversation, extract each row, which is one SMS message.
        rows = conversation.findAll(attrs={"class" : "gc-message-sms-row"})
        for row in rows :                               # for all rows
            #   For each row, which is one message, extract all the fields.
            msgitem = {"id" : conversation["id"]}       # tag this message with conversation ID
            spans = row.findAll("span",attrs={"class" : True}, recursive=False)
            for span in spans :                         # for all spans in row
                cl = span["class"].replace('gc-message-sms-', '')
                msgitem[cl] = (" ".join(span.findAll(text=True))).strip()   # put text in dict
            msgitems.append(msgitem)                    # add msg dictionary to list
    return msgitems

for message in extractsms(voice.sms.html):
    print message['text']
    message['id'].delete()

次のエラーがあります。

Traceback (most recent call last):
   File "/Users/Matthew/Desktop/movieDownloader.py", line 38, in <module>
   message['id'].delete() AttributeError: 'unicode' object has no attribute 'delete'

delete()を正しく使用しているとは思えません。

4

2 に答える 2

0

from googlevoice import Voice

voice = Voice()
voice.login()

for message in voice.sms().messages:
    if message.isRead:
        message.delete()
于 2012-11-07T16:50:07.410 に答える
0

メッセージに対してオブジェクトとして削除アクションを実行します。私はpygooglevoiceのドキュメントで以下のコードを見つけました:

from googlevoice import Voice

voice = Voice()
voice.login()

for message in voice.sms().messages:
    if message.isRead:
        message.delete()
于 2012-11-07T16:53:46.483 に答える