def load_data(path): """ Load datasets Loads Post and Comments datasets and merge them together. :param path: data directory path :param path: str :return: DF of raw data """ # Dropbox client team_dbx = dropbox.DropboxTeam(credentials.dropbox_team_access_token) team_root = team_dbx.with_path_root( dropbox.common.PathRoot.namespace_id( credentials.dropbox_team_namespace_id)) user_dbx = team_root.as_user(credentials.dropbox_team_member_id) # Load Posts and Comments DF _, res_posts = user_dbx.files_download(os.path.join(path, "PolPosts.csv")) posts = pd.read_csv(res_posts.raw, low_memory=False) _, res_comments = user_dbx.files_download( os.path.join(path, "UserComments.csv")) comments = pd.read_csv(res_comments, low_memory=False) # Merge Posts with Comments DFs raw_data = pd.concat([posts, comments], sort=False) return raw_data
def dump_data(df, path): """ Dump cleaned DF :param df: DF of cleaned data :param df: pd.DataFrame :param path: data directory path :param path: str :return: - """ # Dropbox client team_dbx = dropbox.DropboxTeam(credentials.dropbox_team_access_token) team_root = team_dbx.with_path_root( dropbox.common.PathRoot.namespace_id( credentials.dropbox_team_namespace_id)) user_dbx = team_root.as_user(credentials.dropbox_team_member_id) # Dump dump_path = os.path.join(path, "CleanedTextDF_interim.csv") user_dbx.files_upload(bytes(df.to_csv(index=False), "utf-8"), dump_path, mode=dropbox.files.WriteMode.overwrite)
def load_data(path): """ Load Datasets Loads Post dataset. :param path: data directory path :param path: str :return: DF of raw Posts data """ # Dropbox client team_dbx = dropbox.DropboxTeam(credentials.dropbox_team_access_token) team_root = team_dbx.with_path_root( dropbox.common.PathRoot.namespace_id( credentials.dropbox_team_namespace_id)) user_dbx = team_root.as_user(credentials.dropbox_team_member_id) # Load Posts _, res_posts = user_dbx.files_download(os.path.join(path, "PolPosts.csv")) posts = pd.read_csv(res_posts.raw, low_memory=False) return posts
def save_data(data, path, name): """ Persist data (incl. assigned topics) to disk. :param data: DF with assigned topics to persist :type data: pd.DataFrame :param path: data directory path :type path: str :param name: model name :type name: str :return: - """ # Dropbox client team_dbx = dropbox.DropboxTeam(credentials.dropbox_team_access_token) team_root = team_dbx.with_path_root( dropbox.common.PathRoot.namespace_id( credentials.dropbox_team_namespace_id)) user_dbx = team_root.as_user(credentials.dropbox_team_member_id) # Persist to disk persist_fpath = os.path.join(path, "topics", name + ".csv") user_dbx.files_upload(bytes(data.to_csv(index=False), "utf-8"), persist_fpath, mode=dropbox.files.WriteMode.overwrite)
def listlinks(): '''print all public links urls for all members''' for (memberid, email) in getmembers(): links = getlinks(memberid) link_count = len(links) print("Public Links: %s User: %s" % (link_count, email)) for link in links: print(" %s" % link.url) if __name__ == '__main__': print( "This script requires a API token with 'Team Member File Access premissions'" ) token = (input("Enter your token: ")) mode = (input("Enter a mode (either 'list' or 'delete'): ")) dbxt = dropbox.DropboxTeam(token) if mode == "list": listlinks() ## CAUTION: Enabling this mode will allow deletion of unprotected shared links ## This could result in disruption to your team # elif mode == "delete": # delall() else: print("Please enter a mode of list or delete")
path = i.path_lower filedate = findModified(path) print("Last Modified Date: ", filedate) if (filedate < oldestdate): oldestdate = filedate print("-") print("The oldest file in this account is ", oldestdate) ####### # MAIN ####### TOKEN = 'REDACTED' PERSONAL = 'REDACTED' dbx = dropbox.DropboxTeam(TOKEN) #dbx = dropbox.Dropbox(PERSONAL) #membersList = WriteTeamMembers(dbx) #GetUsage(dbx) #LogEvents(dbx) ListFiles(dbx.as_user(PERSONAL)) #getOldDate(dbx.as_user(PERSONAL))
if sys.version.startswith('2'): input = raw_input # pylint: disable=redefined-builtin,undefined-variable,useless-suppression def process_entries(current_state, entries): for entry in entries: if ( isinstance(entry, dropbox.files.FileMetadata) or isinstance(entry, dropbox.files.FolderMetadata) ): current_state[entry.path_lower] = entry elif isinstance(entry, dropbox.files.DeletedMetadata): current_state.pop(entry.path_lower, None) return current_state # Initialize Dropbox API dbx_team = dropbox.DropboxTeam("ACCESS TOKEN") # Prompt for account email email = input("Enter team member email: ") # Select a user via email team_member_info = dbx_team.team_members_get_info( [dropbox.team.UserSelectorArg.email(email)] ).pop() # Verify that user is a valid team member if team_member_info and team_member_info.is_member_info(): team_member_id = team_member_info.get_member_info().profile.team_member_id user_dbx = dbx_team.as_user(team_member_id) else: print("User " + email + " was not found. Exiting...")
import dropbox from dropbox.team_log import EventCategory from dropbox.team_common import TimeRange from datetime import datetime, timedelta import csv import sys dbx = dropbox.DropboxTeam("<ACCESS TOKEN>") headers = ["Timestamp", "Email", "Login Error"] csvwriter = csv.writer(sys.stdout, lineterminator='\n') # Collect login events start = datetime.utcnow() - timedelta(days=30) result = dbx.team_log_get_events(category=EventCategory.logins, time=TimeRange(start_time=start)) events = result.events # Collect additional events if needed while result.has_more: result = dbx.team_log_get_events_continue(result.cursor) events.extend(result.events) csvwriter.writerow(headers) for event in events: if event.event_type.is_login_fail() and event.actor.is_admin(): csvwriter.writerow((event.timestamp, event.actor.get_admin().email, event.details.get_login_fail_details(). error_details.user_friendly_message))
if str(entry.name).endswith(".csv"): interim_results_files.append(str(entry.name)) if results_fname in interim_results_files: interim_results_files.remove(results_fname) for file_name in interim_results_files: _, res = user_dbx.files_download(os.path.join(data_path, file_name)) interim_results.append(pd.read_csv(res.raw)) return pd.concat(interim_results, axis=0) if __name__ == "__main__": # Dropbox client team_dbx = dropbox.DropboxTeam(credentials.dropbox_team_access_token) team_root = team_dbx.with_path_root( dropbox.common.PathRoot.namespace_id( credentials.dropbox_team_namespace_id)) user_dbx = team_root.as_user(credentials.dropbox_team_member_id) # Paths and filenames info_path = "/Data/Info Lists" data_path = "/Data/CSVData/ads" results_fname = "Test_AdLibAll.csv" # Monitoring period constraints monitoring_period_start = date(2019, 9, 8) monitoring_period_stop = date(2019, 9, 29) monitoring_window = (monitoring_period_start, monitoring_period_stop) missing_stop_accounts = [] # bookkeep accounts w/ missing stop dates
import dropbox import sys if sys.version.startswith('2'): input = raw_input # pylint: disable=redefined-builtin,undefined-variable,useless-suppression dbx_team = dropbox.DropboxTeam("<ACCESS_TOKEN>") def process_entries(current_state, entries): for entry in entries: if (isinstance(entry, dropbox.files.FileMetadata) or isinstance(entry, dropbox.files.FolderMetadata)): current_state[entry.path_lower] = entry elif isinstance(entry, dropbox.files.DeletedMetadata): current_state.pop(entry.path_lower, None) return current_state # Prompt for admin account email email = input("Enter team admin email: ") # Select a user via email team_member_info = dbx_team.team_members_get_info( [dropbox.team.UserSelectorArg.email(email)]).pop() # Verify that user is a valid team member, and also a full team admin if (team_member_info and team_member_info.is_member_info() and team_member_info.get_member_info().role.is_team_admin()): team_member_id = team_member_info.get_member_info().profile.team_member_id admin_dbx = dbx_team.as_admin(team_member_id)