

def save_tweets(filename, tweets):
    'Save tweets from dict to file.\n\n    Save tweets from dict to UTF-8 encoded file, one per line:\n        <tweet id (number)> <tweet text>\n    Tweet text is:\n        <date> <<user>> [RT @<user>: ]<text>\n\n    Args:\n        filename: A string representing the file name to save tweets to.\n        tweets: A dict mapping tweet-ids (int) to tweet text (str).\n    '
    if (len(tweets) == 0):
        return
    try:
        archive = open(filename, 'w')
    except IOError as e:
        err(('Cannot save tweets: %s' % str(e)))
        return
    for k in sorted(tweets.keys()):
        try:
            archive.write(('%i %s\n' % (k, tweets[k].encode('utf-8'))))
        except Exception as ex:
            err(('archiving tweet %s failed due to %s' % (filename, unicode(ex))))
    archive.close()

dataset/ETHPy150Open sixohsix/twitter/twitter/archiver.py save_tweets/VarMisuse@120/320 `k`->`filename`