import bz2
import json


def read_zip(filename):
    """Reads tweet zip file from https://archive.org/details/twitterstream.

    Args:
        filename (str)

    Yields:
        dict
    """
    # Decompress and decode .bz2 file
    fbz = bz2.BZ2File(filename, "rb")
    try:
        fdec = fbz.read()
    except IOError:
        return None
    finally:
        fbz.close()
    fdecutf = fdec.decode("utf-8")

    # Loop through each line in file
    for tweet_str in fdecutf.split("\n"):
        try:
            tweet = json.loads(tweet_str)
        except ValueError:
            continue
        if "delete" in tweet.keys():
            continue
        yield tweet