Commit 478363e5 authored by Francesco Poldi's avatar Francesco Poldi Committed by GitHub

Merge pull request #134 from haccer/dev

Pandas feature
parents 485291d2 dd5aaaba
import warnings
from time import strftime, localtime
import pandas as pd
from .elasticsearch import *
_blocks = []
def update(_tweet, session):
def update(Tweet, session):
day = weekday(strftime("%A", localtime(Tweet.datetime)))
dt = "{} {}".format(Tweet.datestamp, Tweet.timestamp)
......@@ -31,27 +32,34 @@ def get():
df = pd.DataFrame(_blocks)
return df
def save(_dataframe, _dataname, _filename, _type):
if not _dataname:
def save(_filename, _dataframe, **options):
if options.get("dataname"):
_dataname = options.get("dataname")
else:
_dataname = "twint"
if not _type or _type == "HDF5":
_store = pd.HDFStore(_filename)
_store[_dataname] = _dataframe
elif _type == "Pickle":
_dataframe.to_pickle(_filename)
if not options.get("type"):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
_store = pd.HDFStore(_filename)
_store[_dataname] = _dataframe
_store.close()
elif options.get("type") == "Pickle":
with warnings.catch_warnings():
warnings.simplefilter("ignore")
_dataframe.to_pickle(_filename)
else:
print("Please specify: DataFrame, DataFrame name, filename and type (HDF5, default, or Pickle")
print("Please specify: filename, DataFrame, DataFrame name and type (HDF5, default, or Pickle")
def read(_dataframe, _dataname, _filename, _type):
if not _dataname:
def read(_filename, **options):
if not options.get("dataname"):
_dataname = "Twint"
if not _type or _type == "HDF5":
if not options.get("type"):
_store = pd.HDFStore(_filename)
df = _store[_dataname]
return df
elif _type == "Pickle":
elif options.get("type") == "Pickle":
df = pd.read_pickle(_filename)
return df
else:
......
VERSION = (1, 1, 3, 3)
VERSION = (1, 1, 3, 4)
__version__ = '.'.join(map(str, VERSION))
from datetime import datetime
from . import Pandas
from . import db, elasticsearch, format, write
from . import db, elasticsearch, format, write, Pandas
from .tweet import Tweet
from .user import User
......@@ -30,9 +29,9 @@ def _output(obj, output, config):
write.Json(obj, config)
else:
write.Text(output, config.Output)
if config.Pandas:
Pandas.update(obj, config.Session)
Pandas.update(obj, config.Essid)
if config.Elasticsearch:
if config.Store_object:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment