def parse(args):
    with open(args.output, 'w+', encoding="utf-8") as output:
        print("Opened", args.output)
        if not args.compress:
            csv_writer = csv.writer(output, dialect=args.dialect)
            if not args.nolabel:
                csv_writer.writerow([a.title for a in args.attributes])
        count = 0
        tweets = set()

        for json_object in json_entries(args):
            #Check for duplicates
            if args.id:
                identity = args.id.getElement(json_object)
                if identity in tweets:
                    continue
                tweets.add(identity)

            #Check for time restrictions.
            if args.start or args.end:
                tweet_time = strptime(args.date.getElement(json_object), args.dateformat)
                if args.start and args.start &gt; tweet_time:
                    continue
                if args.end and args.end &lt; tweet_time:
                    continue

#            #check if retweet.
#            if "retweeted_status" in json_object:
#                continue

            #Check for hashtag.
            if args.hashtag:
                for entity in json_object['entities']["hashtags"]:
                    if entity['text'].lower() == args.hashtag:
                        break
                else:
                    continue

            #compression algorithm.
            if args.compress:
                json.dump(json_object, output)
                output.write("\n")

            #Write this tweet to csv.
            else:
                item = [i.getElement(json_object) for i in args.attributes]
                csv_writer.writerow(item)

            count += 1

        print("Recorded {} items.".format(count))
        if tweets:
            print("largest id:", max(tweets))
