Exemple #1
0
    def parse_posts(self, file_name):
        time_handler = TimeHandler()
        time_handler.prompt_for_input()

        with open(file_name, 'rb') as csvfile:
            reader = csv.DictReader(csvfile)
            time_from_ = time_handler.from_unixtime_to_csvtime(
                time_handler.time_from)
            time_until_ = time_handler.from_unixtime_to_csvtime(
                time_handler.time_until)
            for row in reader:
                row_time_created = row['time']
                if time_from_ <= row_time_created <= time_until_:
                    self.posts.append(row['id'])
            pa = PostAggregator()
            df = pd.DataFrame(data=self.posts, columns=["IDs"])
            print(df)
            for post in self.posts:
                pa.multiple_inputs(post)
Exemple #2
0
def edit_delete(selected_row, row_list, csv_file):
    task = True
    while task:
        clear()
        print("Selected Row: {}".format(", ".join(selected_row)))
        print("Edit or Delete\n")
        print("1. Edit")
        print("2. Delete\n")
        print("Please enter the number of the option you wish to choose.")
        choice = input("> ")
        if choice == '1':
            index_tracker = 0
            for key, value in enumerate(row_list):
                if value == selected_row:
                    del row_list[key]
                    index_tracker += key
                    break
            while True:
                clear()
                print("Selected Row: {}".format(", ".join(selected_row)))
                print("Choose which detail you wish to edit\n")
                print("1. Date")
                print("2. Task Name")
                print("3. Time Spent")
                print("4. Notes")
                print("5. Done\n")
                print("Please enter the number of the option you wish" +
                      " to choose.")
                print("Selecting 'Done' will updated the log file and will")
                print("return you to the previous menu.")
                choice = input("> ")
                if choice == '1':
                    del selected_row[0]
                    new_date = get_date("Date Editing")
                    selected_row.insert(0, new_date)
                elif choice == '2':
                    del selected_row[1]
                    while True:
                        clear()
                        tester = []
                        task_name = input("Enter new task name: ")
                        if len(task_name) > 0:
                            for i in task_name:
                                if i != " ":
                                    tester.append(1)
                        if len(tester) > 0:
                            break
                        else:
                            print("Invalid Task Name")
                            input("Press Enter")
                    selected_row.insert(1, task_name)
                elif choice == '3':
                    del selected_row[2]
                    while True:
                        clear()
                        print("Edit the amount of time spent")
                        hours = input("Hours: ")
                        minutes = input("Minutes: ")
                        if hours == '':
                            hours = '0'
                        if minutes == '':
                            minutes = '0'
                        try:
                            int(hours)
                            int(minutes)
                        except ValueError:
                            print("Invalid Entry")
                            input("Press Enter")
                        else:
                            task_duration = TimeHandler(
                                int(hours), int(minutes))
                            h_fmt, m_fmt = task_duration.get_hours_minutes()
                            time_spent = "Hours:{} Minutes:{}".format(
                                h_fmt, m_fmt)
                            break
                    selected_row.insert(2, time_spent)
                elif choice == '4':
                    clear()
                    del selected_row[3]
                    notes = input("Enter New notes or press enter to" +
                                  "leave notes blank: ")
                    tester2 = []
                    if len(notes) > 0:
                        for i in notes:
                            if i != " ":
                                tester2.append(1)
                    if len(tester2) < 1:
                        notes = 'N/A'
                    selected_row.insert(3, notes)
                elif choice == '5':
                    row_list.insert(index_tracker, selected_row)
                    with open(csv_file, 'w') as csvfile:
                        fieldnames = [
                            'Date', 'Task Name', 'Time Spent', 'Notes'
                        ]
                        writer = csv.DictWriter(csvfile,
                                                fieldnames=fieldnames,
                                                lineterminator='\n')
                        writer.writerow({
                            'Date': 'Date',
                            'Task Name': 'Task Name',
                            'Time Spent': 'Time Spent',
                            'Notes': 'Notes'
                        })
                        for row in row_list:
                            writer.writerow({
                                'Date': row[0],
                                'Task Name': row[1],
                                'Time Spent': row[2],
                                'Notes': row[3]
                            })
                    task = False
                    break
                else:
                    print("Invalid Input")
                    input("Press Enter")

        elif choice == '2':
            row_list.remove(selected_row)
            with open(csv_file, 'w') as csvfile:
                fieldnames = ['Date', 'Task Name', 'Time Spent', 'Notes']
                writer = csv.DictWriter(csvfile,
                                        fieldnames=fieldnames,
                                        lineterminator='\n')
                writer.writerow({
                    'Date': 'Date',
                    'Task Name': 'Task Name',
                    'Time Spent': 'Time Spent',
                    'Notes': 'Notes'
                })
                for row in row_list:
                    writer.writerow({
                        'Date': row[0],
                        'Task Name': row[1],
                        'Time Spent': row[2],
                        'Notes': row[3]
                    })
            task = False
            break
        else:
            print("Invalid Input")
            input("Press Enter")
Exemple #3
0
 def write_to_log(self):
     task_date = get_date("Task Date")
     while True:
         clear()
         print("Task Date: {}\n".format(task_date))
         tester = []
         task_name = input("Please enter the name of your task: ")
         # Task name
         if len(task_name) > 0:
             for i in task_name:
                 if i != " ":
                     tester.append(1)
         if len(tester) > 0:
             break
         else:
             print("Invalid Task Name")
             input("Press Enter")
     while True:
         clear()
         print("Task Date: {}".format(task_date))
         print("Task Name: {}\n".format(task_name))
         print("Enter the amount of time spent")
         hours = input("Hours: ")
         minutes = input("Minutes: ")
         if hours == '':
             hours = '0'
         if minutes == '':
             minutes = '0'
         try:
             int(hours)
             int(minutes)
         except ValueError:
             print("Invalid Entry")
             input("Press Enter")
         else:
             task_duration = TimeHandler(int(hours), int(minutes))
             hours_fmt, minutes_fmt = task_duration.get_hours_minutes()
             time_spent = "Hours:{} Minutes:{}".format(
                 hours_fmt, minutes_fmt)
             # Time spent
             break
     clear()
     print("Task Date: {}".format(task_date))
     print("Task Name: {}".format(task_name))
     print("Time Spent: {}\n".format(time_spent))
     notes = input("Enter additional notes (Optional): ")
     # Notes
     tester2 = []
     if len(notes) > 0:
         for i in task_name:
             if i != " ":
                 tester2.append(1)
     if len(tester2) < 1:
         notes = 'N/A'
     with open(self.spreadsheet, 'a') as csvfile:
         fieldnames = ['Date', 'Task Name', 'Time Spent', 'Notes']
         writer = csv.DictWriter(csvfile,
                                 fieldnames=fieldnames,
                                 lineterminator='\n')
         writer.writerow({
             'Date': task_date,
             'Task Name': task_name,
             'Time Spent': time_spent,
             'Notes': notes
         })
Exemple #4
0
 def search_log(self):
     row_list = get_row_list(self.spreadsheet)
     fmt = '%m/%d/%Y'
     while True:
         clear()
         print("Log Search Menu\n")
         print("1. Search by date")
         print("2. Search by time spent")
         print("3. Search by exact match or pattern")
         print("4. Page through individual entries")
         print("5. Previous menu\n")
         print("Please enter the number of the option you wish to choose.")
         user_choice = input("> ")
         if user_choice == '1':
             search_by_date = True
             while search_by_date:
                 clear()
                 print("Search an entry by date\n")
                 print("Would you like to enter a specific date range?")
                 user_choice2 = input("Y/N ")
                 if user_choice2.upper() == 'Y':
                     fmt_date_list = []
                     search_list = []
                     start_date = get_date("Starting Date")
                     end_date = get_date("Ending Date")
                     start_date_fmt = datetime.datetime.strptime(
                         start_date, fmt)
                     end_date_fmt = datetime.datetime.strptime(
                         end_date, fmt)
                     for result in perdelta(
                             start_date_fmt,
                             end_date_fmt + datetime.timedelta(days=1),
                             datetime.timedelta(days=1)):
                         fmt_date_list.append(
                             datetime.datetime.strftime(result, fmt))
                     for i in row_list:
                         if i[0] in fmt_date_list:
                             search_list.append(i)
                     get_options_to_edit(search_list, row_list,
                                         self.spreadsheet)
                     search_by_date = False
                 else:
                     selected_dates = []
                     task_date = get_date(
                         "Chosen date will list all entrie" +
                         "s with matching Task Date")
                     for i in row_list:
                         if i[0] == task_date:
                             selected_dates.append(i)
                     get_options_to_edit(selected_dates, row_list,
                                         self.spreadsheet)
                     search_by_date = False
         elif user_choice == '2':
             selected_entries = []
             while True:
                 clear()
                 print("Seach an entry by time\n")
                 hours = input("Hours: ")
                 minutes = input("Minutes: ")
                 if hours == '':
                     hours = '0'
                 if minutes == '':
                     minutes = '0'
                 try:
                     int(hours)
                     int(minutes)
                 except ValueError:
                     print("Invalid Entry")
                     input("Press Enter")
                 else:
                     task_duration = TimeHandler(int(hours), int(minutes))
                     h_fmt, m_fmt = task_duration.get_hours_minutes()
                     time_spent = "Hours:{} Minutes:{}".format(h_fmt, m_fmt)
                     # Time spent
                     break
             for row in row_list:
                 if row[2] == time_spent:
                     selected_entries.append(row)
             get_options_to_edit(selected_entries, row_list,
                                 self.spreadsheet)
         elif user_choice == '3':
             clear()
             selected_entries = []
             while True:
                 clear()
                 print(
                     "Search an entry by exact match or regular expression\n"
                 )
                 print("Please enter text or regular expression" +
                       " to match entries")
                 print("Do not add spaces after commas.")
                 string = input("> ")
                 if len(string) < 1:
                     print("Invalid Input")
                     input("Press Enter")
                 else:
                     break
             search_string = '(?P<results>%s)' % string
             for row in row_list:
                 row_string = ",".join(row)
                 parse = re.search(r'%s' % search_string, row_string, re.I)
                 if parse is not None:
                     selected_entries.append(row)
             get_options_to_edit(selected_entries, row_list,
                                 self.spreadsheet)
         elif user_choice == '4':
             page_range = list(range(0, len(row_list)))
             page = 0
             while True:
                 clear()
                 if len(row_list) == 0:
                     print("You don't have any entries to view.")
                     input("Press enter")
                     break
                 else:
                     current_row = row_list[page]
                     print("Entry #: {}\n".format(page + 1))
                     print("Date {}".format(current_row[0]))
                     print("Task Name: {}".format(current_row[1]))
                     print("Time Spent: {}".format(current_row[2]))
                     print("Notes: {}\n".format(current_row[3]))
                     print("1. Next Entry")
                     print("2. Previous Entry")
                     print("3. Edit Entry")
                     print("4. Back to previous menu\n")
                     print("Please enter the number of the option" +
                           " you wish to choose.")
                     user_choice = input("> ")
                     if user_choice == '1':
                         if page + 1 in page_range:
                             page = page + 1
                         else:
                             print("There are no more further entries.")
                             input("Press Enter")
                     elif user_choice == '2':
                         if page - 1 in page_range:
                             page = page - 1
                         else:
                             print("There are no more previous entries.")
                             input("Press Enter")
                     elif user_choice == '3':
                         edit_delete(row_list[page], row_list,
                                     self.spreadsheet)
                         break
                     elif user_choice == '4':
                         break
                     else:
                         print("Invalid Input")
                         input("Press Enter")
         elif user_choice == '5':
             break
         else:
             print("Invalid Input")
             input("Press Enter")
Exemple #5
0
import poly_renderer as rend
import tri_handler as th
import png
from time_handler import TimeHandler
import sys
import random

time_h = TimeHandler()
time_h.start_timing("setup")

sys.setrecursionlimit(50000)  # otherwise pickle will throw a RecursionError
random.seed(
    0
)  # makes debugging easier, since results will be the same under identical conditions

reader = png.Reader("input\\crystal.png")

img = reader.read()
width = img[0]
row_iter = img[2]
hasAlpha = img[3]['alpha']

pixel_array = []

if hasAlpha:
    for r in row_iter:
        r_array = []
        for p in range(0, width * 4, 4):
            for c in range(p, p + 3):
                r_array.append(r[c])
        pixel_array.append(r_array)
Exemple #6
0
def main(stdscr):

    holdstdout = StdOutWrapper()
    sys.stdout = holdstdout
    sys.stderr = holdstdout

    #stdscr = curses.initscr()

    screen_size = stdscr.getmaxyx()
    height = screen_size[0]
    width = screen_size[1]
    hincrement = int(height / 3)
    wincrement = int(width / 3)
    upper_left = (0, 0)
    upper_middle = (0, wincrement)
    upper_right = (0, 2 * wincrement)
    middle_left = (hincrement, 0)
    middle_middle = (hincrement, wincrement)
    middle_right = (hincrement, 2 * wincrement)
    lower_left = (2 * hincrement, 0)
    lower_middle = (2 * hincrement, wincrement)
    #lower_right= (2 * hincrement, 2 * wincrement)

    # Skills    | Spells   | Loadout
    # HUD       | Map      | Inventory
    # Terminal  | Status   | Inventory

    # Terminal green
    curses.init_pair(1, 46, curses.COLOR_BLACK)
    # Dull red
    curses.init_pair(2, 196, curses.COLOR_BLACK)
    # Dull Teal
    curses.init_pair(3, curses.COLOR_CYAN, curses.COLOR_BLACK)
    # Black on Grey
    curses.init_pair(4, curses.COLOR_BLACK, 244)
    # bronze
    curses.init_pair(5, 208, curses.COLOR_BLACK)
    curses.init_pair(6, 208, 130)
    # steel
    curses.init_pair(7, 252, curses.COLOR_BLACK)
    curses.init_pair(8, 253, 247)
    # mithril
    curses.init_pair(9, 117, curses.COLOR_BLACK)
    curses.init_pair(10, 117, 33)
    # adamant
    curses.init_pair(11, 99, curses.COLOR_BLACK)
    curses.init_pair(12, 52, 99)

    # demon
    curses.init_pair(13, 92, curses.COLOR_BLACK)
    curses.init_pair(14, 52, 99)

    # spark
    curses.init_pair(15, 92, curses.COLOR_BLACK)
    curses.init_pair(16, 52, 99)

    # night
    curses.init_pair(17, 92, curses.COLOR_BLACK)
    curses.init_pair(18, 52, 99)

    # cooked meat
    curses.init_pair(19, 124, curses.COLOR_BLACK)

    # leather
    curses.init_pair(20, 130, curses.COLOR_BLACK)

    # oak
    curses.init_pair(21, 172, curses.COLOR_BLACK)

    # maple
    curses.init_pair(22, 167, curses.COLOR_BLACK)

    # willow
    curses.init_pair(23, 137, curses.COLOR_BLACK)

    # flax
    curses.init_pair(100, 100, curses.COLOR_BLACK)

    # gold
    curses.init_pair(253, 220, curses.COLOR_BLACK)
    # white
    curses.init_pair(254, 252, curses.COLOR_BLACK)
    # box color, dull grey
    curses.init_pair(255, 240, curses.COLOR_BLACK)

    terwin = curses.newwin(hincrement, wincrement, lower_left[0],
                           lower_left[1])
    terwin.attron(curses.color_pair(255))
    terwin.box()
    ter_panel = curses.panel.new_panel(terwin)
    ter_panel.top()

    hudwin = curses.newwin(hincrement, wincrement, middle_left[0],
                           middle_left[1])
    hudwin.attron(curses.color_pair(255))
    hudwin.box()
    hud_panel = curses.panel.new_panel(hudwin)
    hud_panel.top()

    invwin = curses.newwin(hincrement * 2, wincrement, middle_right[0],
                           middle_right[1])
    invwin.attron(curses.color_pair(255))
    invwin.box()
    inv_panel = curses.panel.new_panel(invwin)
    inv_panel.top()

    stswin = curses.newwin(hincrement, wincrement, lower_middle[0],
                           lower_middle[1])
    stswin.attron(curses.color_pair(255))
    stswin.box()
    sts_panel = curses.panel.new_panel(stswin)
    sts_panel.top()

    sklwin = curses.newwin(hincrement, wincrement, upper_left[0],
                           upper_left[1])
    sklwin.attron(curses.color_pair(255))
    sklwin.box()
    skl_panel = curses.panel.new_panel(sklwin)
    skl_panel.top()

    eqpwin = curses.newwin(hincrement, wincrement, upper_right[0],
                           upper_right[1])
    eqpwin.attron(curses.color_pair(255))
    eqpwin.box()
    eqp_panel = curses.panel.new_panel(eqpwin)
    eqp_panel.top()

    mapwin = curses.newwin(hincrement, wincrement, middle_middle[0],
                           middle_middle[1])
    mapwin.attron(curses.color_pair(255))
    mapwin.box()
    map_panel = curses.panel.new_panel(mapwin)
    map_panel.top()

    splwin = curses.newwin(hincrement, wincrement, upper_middle[0],
                           upper_middle[1])
    splwin.attron(curses.color_pair(255))
    splwin.box()
    spl_panel = curses.panel.new_panel(splwin)
    spl_panel.top()

    curses.start_color()

    curses.cbreak()
    curses.noecho()
    terwin.keypad(1)
    terwin.idcok(False)

    try:

        var_handler = VarHandler()

        command_processor = CommandProcessor(var_handler)
        var_handler.bind('command_processor', command_processor)

        io_handler = IOHandler(terwin, var_handler)
        var_handler.bind('io_handler', io_handler)

        hud_handler = HUDHandler(hudwin, var_handler)
        var_handler.bind('hud_handler', hud_handler)

        status_handler = StatusHandler(stswin)
        var_handler.bind('status_handler', status_handler)

        player = Player(sklwin, var_handler)
        var_handler.bind('player', player)

        inventory_handler = InventoryHandler(invwin, eqpwin, var_handler)
        var_handler.bind('inventory_handler', inventory_handler)

        location_handler = LocationHandler(mapwin, var_handler)
        var_handler.bind('location_handler', location_handler)

        time_handler = TimeHandler()
        var_handler.bind('time_handler', time_handler)

        spell_handler = SpellHander(splwin, var_handler)
        var_handler.bind('spell_handler', spell_handler)

        combat_handler = CombatHandler(var_handler)
        var_handler.bind('combat_handler', combat_handler)

        start = location_handler.spawn_location('entervale')
        location_handler.spawn_location('forest')
        start.move("mine")

        io_handler.output("Welcome to pyscape", curses.color_pair(3),
                          curses.A_BOLD)
        hud_handler.text_update()
        hud_panel.top()
        inventory_handler.update_inv_window()
        curses.panel.update_panels()

        while True:
            curses.curs_set(1)
            input = io_handler.get_input("~~~~~~~:", curses.color_pair(1))
            output = command_processor.receive_command(input)
            io_handler.output(output[0], output[1])
            hud_handler.text_update()
            hud_panel.top()
            #inventory_handler.draw_bank()
            curses.panel.update_panels()

    except KeyboardInterrupt:
        terwin.addstr("exiting")
        exit(0)

    finally:
        terwin.keypad(0)
        curses.nocbreak()
        curses.echo()
        curses.endwin()
        sys.stdout = sys.__stdout__
        sys.stderr = sys.__stderr__
        sys.stdout.write(holdstdout.get_text())
Exemple #7
0
class Aggregator(object):

    # Each aggregator needs an Access Token (its 'gateway' into the Facebook Graph),
    # a Graph object which is how it will make calls to the graph,
    # a Time Handler (defined in time_handler.py) which will do all of the time functions.
    # The obj_name and obj_type represent a single object (post, like, or comment) from the Graph API.
    # Todo: Replace all (defunct?) time methods in this class and delegate them to the time_handler
    def __init__(self):
        self.access_token = get_app_access_token(FACEBOOK_APP_ID,
                                                 FACEBOOK_SECRET_ID)
        self.graph = facebook.GraphAPI(self.access_token)
        self.obj_name = None
        self.obj_type = None
        self.time_handler = TimeHandler()

    # Todo: Delegate this to time_handler
    def input_time(self, input_):
        while True:
            input_ = self.create_time(input_)
            if input_ == -1:  # User entered a bad format; try again
                print "Invalid format. The format is: Y m d H M S (ex: 2013 04 20 03 21 43 for 04/20/2013 @ 3:21:43)"
                continue
            else:
                # Successfully parsed, exit
                break
        return input_

    # Todo: Delegate this to time_handler
    @staticmethod
    def create_time(time_in):
        try:
            time_ary = time_in.split()
            if not time_ary:  # User entered nothing
                return 0
            elif len(time_ary) != 6:
                print "Invalid format."
                return -1
            time_dict = {
                'Y': int(time_ary[0]),
                'm': int(time_ary[1]),
                'd': int(time_ary[2]),
                'H': int(time_ary[3]),
                'M': int(time_ary[4]),
                'S': int(time_ary[5])
            }
            formatted_time = datetime.datetime(
                time_dict['Y'], time_dict['m'], time_dict['d'], time_dict['H'],
                time_dict['M'], time_dict['S']) + datetime.timedelta(hours=-4)
            time_since_epoch = calendar.timegm(formatted_time.timetuple())
            print time_since_epoch
            return time_since_epoch
        except TypeError:
            print "TypeError: stop doing funky stuff with data structures"
            return -1
        except ValueError:
            print "ValueError: times must not be out of conventional bounds"
            return -1

    # def grab_date_range(self):
    #
    #     while True:
    #         self.time_from = raw_input('Please enter the time you\'d like to gather from. Leave blank for "from the beginning'
    #                                    ' of time". \nThe format is: Y m d H M S (ex: 2013 04 20 03 21 43 for 04/20/2013 @ 03:21:43)\n')
    #         self.time_from = self.input_time(self.time_from)
    #         if self.time_from == 0:  # If nothing was entered, make the time to gather from the beginning of the epoch
    #             self.time_from = 1
    #             break
    #         elif self.time_from == -1:
    #             continue
    #         else:
    #             break
    #
    #     while True:
    #         self.datetime_from = from_unix_to_datettime(self.time_from)
    #         self.time_until = raw_input('Please enter the time you\'d like to gather until. Leave blank for "until now". \nThe format is: Y m d H M S\n')
    #         self.time_until = self.input_time(self.time_until)
    #         if self.time_until == -1:
    #             continue
    #         elif self.time_until == 0:
    #             self.time_until = calendar.timegm(datetime.datetime.timetuple(datetime.datetime.now()))
    #             break
    #         else:
    #             break

    # This function will create a directory for each page that the csv_writer can write to.
    # Example: ./data/CNN/2015-04-15/posts/[email protected]_posts.csv
    # is a collection of posts gathered on 4-15-2015 at 9:12 PM
    def generate_path(self, type_):
        path = "./data/" + self.obj_name + "/" + str(
            datetime.datetime.now().date()) + "/" + type_
        if not os.path.exists(path):
            try:
                os.makedirs(path)
            except OSError:
                print "Could not create directory!"
        return path + "/" + self.obj_name + "_@" + str(datetime.datetime.now(
        ).time().strftime("%H.%M.%S")) + "_" + type_ + ".csv"

    # This function will grab the ID from the user, check to see if it actually exists, and then prompt
    # the user if they would like to specify a date range.
    def grab_fb_object_num(self, type_):
        while True:
            while True:
                self.fb_object_num = raw_input('Please enter the ' + type_ +
                                               ' ID: ')
                try:
                    self.page_object = self.graph.get_object(
                        self.fb_object_num)
                    break
                except facebook.GraphAPIError:
                    print "The " + type_ + " you requested does not exist. Please try again.\n"
                    continue

            self.time_handler.prompt_for_input()

            break