def save_tweets(filename, tweets):
    """Save tweets from dict to file.

    Save tweets from dict to UTF-8 encoded file, one per line:
        <tweet id (number)> <tweet text>
    Tweet text is:
        <date> <<user>> [RT @<user>: ]<text>

    Args:
        filename: A string representing the file name to save tweets to.
        tweets: A dict mapping tweet-ids (int) to tweet text (str).
    """
    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" % (k, unicode(ex)))

    archive.close()
dataset/ETHPy150Open sixohsix/twitter/twitter/archiver.py/save_tweets/original