Repository: twintproject/twint
File: twint/output.py (Python)

Code before:
from .storage import db, elasticsearch, write, panda

tweets_object = []

def datecheck(datestamp, config):
    if config.Since and config.Until:
        d = int(datestamp.replace("-", ""))
        s = int(config.Since.replace("-", ""))
        if d < s:
            return False
    return True

def is_tweet(tw):
    try:
        tw.find("div")["data-item-id"]
        return True
    except:
        return False

def _output(obj, output, config):
    if config.Output != None:
        if config.Store_csv:
            write.Csv(obj, config)
        elif config.Store_json:
            write.Json(obj, config)
        else:
            write.Text(output, config.Output)

    if config.Pandas:
        panda.update(obj, config.Essid)
    if config.Elasticsearch:
        if config.Store_object:
            tweets_object.append(obj)
        else:
            print(output, end=".", flush=True)
    else:
        if config.Store_object:
            tweets_object.append(obj)
        else:
            try:
                print(output)
            except UnicodeEncodeError:
                pass

async def Tweets(tw, location, config, conn):
    copyright = tw.find("div", "StreamItemContent--withheld")
    if copyright is None and is_tweet(tw):
        tweet = Tweet(tw, location, config)
        if datecheck(tweet.datestamp, config):
            output = format.Tweet(config, tweet)
            

Review comment (security):
What kind of errors are you expecting? 
If the file does not exist, then it will be created.
If the file already exists the data will be appended.

Errors that could be expected are external to Twint, such of could be "permission errors" and so the user that's running the process can not write to the file or create a file in the directory.

Looking forward to better understand your point.

Code after:
from .storage import db, elasticsearch, write, panda

tweets_object = []

def datecheck(datestamp, config):
    if config.Since and config.Until:
        d = int(datestamp.replace("-", ""))
        s = int(config.Since.replace("-", ""))
        if d < s:
            return False
    return True

def is_tweet(tw):
    try:
        tw.find("div")["data-item-id"]
        return True
    except:
        return False

def _output(obj, output, config):
    if config.Output != None:
        if config.Store_csv:
            try :
                write.Csv(obj, config)
            except Exception as e:
                print("Error: " + str(e))
        elif config.Store_json:
            write.Json(obj, config)
        else:
            write.Text(output, config.Output)

    if config.Pandas:
        panda.update(obj, config.Essid)
    if config.Elasticsearch:
        if config.Store_object:
            tweets_object.append(obj)
        else:
            print(output, end=".", flush=True)
    else:
        if config.Store_object:
            tweets_object.append(obj)
        else:
            try:
                print(output)
                pass
            except UnicodeEncodeError:
                print("unicode error")

async def Tweets(tw, location, config, conn):
    copyright = tw.find("div", "StreamItemContent--withheld")
    if copyright is None and is_tweet(tw):