def SearchForEntriesWith(self, key, value): result = []; if key: key = key.title(); else: return "Key is required for searching"; if not value: return "I have no idea what I am looking for. Please provide a value"; if key == "Date": return FindEntryByDate(key); if key == "Author": return FindEntriesByAuthor(key); for entryName in self.EntryFileNames: filePath = "AgendaEntries/" + entryName; with open(filePath) as readObj: entryTxt = json.load(readObj); if entryTxt[key]: for text in entryTxt[key]: if value in text: print("I found the value in this entry.") loadedEntry = Entry(entryTxt['Date'], entryTxt['Author'], entryTxt['Title'], entryTxt['Goals'], entryTxt['Notes']); result.append(loadedEntry); break; else: continue; return result;
def parse_entry(self, stream): format = "<BBHHHII16s" size = struct.calcsize(format) data = stream.read(size) assert(len(data) == size) B_used, file_type, start_addr, end_addr, reserved_a, tape_pos, reserved_b, file_name = struct.unpack(format, data) # B_used > 1: memory snapshot #file_type = { # 1541 file type # 0x82: "PRG", # 0x81: "SEQ", # # etc. # !=0 => PRG #}.get(file_type) or file_type # end_addr == 0xc3c6 is by a faulty tool; TODO loading all entries, sort by ascending order of offset into T64 (+2 for load addr which is part of the file). B_used, file_type, start_addr, end_addr, reserved_a, tape_pos, reserved_b, file_name = struct.unpack(format, data) assert(B_used in [0,1]) file_name = file_name.rstrip(b"\x20") # b"\0") # 0x53 #file_name = file_name.decode("petascii") return(Entry(B_used = B_used > 0, file_type = file_type, start_addr = start_addr, end_addr = 0, # unreliable reserved_a = reserved_a, tape_pos = tape_pos, reserved_b = reserved_b, file_name = file_name))
def LoadEntry(self, entryName): filePath = "AgendaEntries/" + entryName; with open(filePath) as LoadObj: entry = json.load(LoadObj); loadedEntry = Entry(entry['Date'], entry['Author'], entry['Title'], entry['Goals'], entry['Notes']); #self.Entries.append(loadedEntry); return loadedEntry;
def load_header(self): # TODO mangle back to C64 format (16 char filename). file_name = os.path.basename(self.file_name) print("loading header PRG") tape_pos = 0 return Entry(B_used=True, file_type=self.FILE_TYPE, start_addr=self.start_addr, end_addr=self.end_addr, reserved_a=0, tape_pos=tape_pos, reserved_b=0, file_name = file_name)
def CreateEntry(self, author, title, entryDate=None, goals=[], notes=[]): if not entryDate: entryDate = self.FindNextMeetingDate(); searchResult = self.EntryExists(entryDate, title, author); if searchResult: return "An entry for this entry date has already been created."; else: newEntry = Entry(entryDate, author, title, goals, notes); #self.Entries.append(newEntry); #self.EntryFileNames.append(newEntry.GetFileName()); self.WriteEntry(newEntry); self.WriteEntryHeader(newEntry); #I should add some exception handling return newEntry;
def newEntries(self): body = ['<ul>'] for feed, entries in self.newentries: body.append(u' <li>%s</li>\n <ul>' % feed) for e in entries: body.append(u' <li>%s</li>' % e.newSummary()) body.append(' </ul>') body.append('</ul>') if len(body) > 2: e = Entry() e.setEntry('Latest news (%s)' % time.strftime('%H:%M:%S'), u'\n'.join(body)) e.setMeta(source='plagg') e.write(self.newspath, '.txt', overwrite=True, fname='Latest')
def load_header(self, file_name): file_name = os.path.basename( self.file_name ) # TODO mangle back to C64 format (16 char filename). file_type = 0x82 # PRG #type_, file_name, start_addr, stop_addr, data = tape_loader.load_header(file_name) print("loading header PRG") #return(file_type, file_name, self.start_addr, self.end_addr) tape_pos = 0 return (Entry(B_used=True, file_type=file_type, start_addr=self.start_addr, end_addr=self.end_addr, reserved_a=0, tape_pos=tape_pos, reserved_b=0, file_name=file_name))
async def check_dupes(ctx): entries = collections.defaultdict(lambda: []) async with ctx.typing(): async for message in entry_channel_history(limit=None): match = URL_RE.search(message.content) if not match: continue entries[message.author.id].append( Entry(message.author.id, match.group(1), message.id)) out = [] for user, chars in entries.items(): if len(chars) < 2: continue member = bot.get_guild(SERVER_ID).get_member(user) warn = f"__{member} has {len(chars)} entries__\nin order (newest first):\n" for char in chars: warn += f"{char.message_link}\n" out.append(warn.strip()) await ctx.send('\n\n'.join(out))
async def get_reactions(ctx): entries = collections.defaultdict(lambda: []) async with ctx.typing(): async for message in entry_channel_history(limit=None): match = URL_RE.search(message.content) if not match: continue if message.reactions: entries[message.author.id].append( Entry(message.author.id, match.group(1), message.id, message.reactions[0].count - 1)) # -1 for bot to_sort = list(entries.items()) sorted_entries = sorted(to_sort, key=lambda e: e[1][0].votes, reverse=True) top_10 = [] for top in sorted_entries[:10]: user, entries = top entry = entries[0] top_10.append(f"<@{user}> ({entry.votes}): <{entry.char_link}>") out = '\n'.join(top_10) await ctx.send(f"__Top 10__\n{out}")
def option_two(self, company_name: str, chart_of_accounts: List[Account]) -> int: while True: print("Debit or Credit? Type \"D\" for Debit or \"C\" for Credit") deb_or_cred = input("") if deb_or_cred.upper() == "D": entry_type = "DEBIT" elif deb_or_cred.upper() == "C": entry_type = "CREDIT" else: print("Not an option. Next time follow instructions.") break print("Which Account does it go in?") for account in chart_of_accounts: print(f'{account.acc_name}') entry_account = input("") entry_amount = input("What is the amount?") entry_day = input("What is the day of the transaction?") entry_month = input("Month?") entry_year = input("Year?") for account in chart_of_accounts: if account.acc_name == entry_account: if account.acc_type == "Asset" or account.acc_type == "Expense": if entry_type == "DEBIT": account.acc_balance += float(entry_amount) elif entry_type == "CREDIT": account.acc_balance -= float(entry_amount) elif account.acc_type == "Liability" or account.acc_type == "Equity" or account.acc_type == "Income": if entry_type == "DEBIT": account.acc_balance -= float(entry_amount) elif entry_type == "CREDIT": account.acc_balance += float(entry_amount) print(entry_type) print(entry_amount) print(entry_account.upper()) print("{}-{}-{}".format(entry_month, entry_day, entry_year)) entry_date = datetime.datetime.now() self.data.append( Entry(type=entry_type, amount=float(entry_amount), account=entry_account.upper(), day=entry_day, month=entry_month, year=entry_year, entry_date=entry_date.date())) entry_diff = self.calculations.total_debs_and_creds((self.data)) if entry_diff != 0: print( "Debits and Credits do not equal, add another entry? (The difference is {})" .format(entry_diff)) another_entry = input("Do you want to add more entries? Y/N") if another_entry.upper() == "Y": print("") elif another_entry.upper() == "N": break else: print("Wrong answer") break else: break
def add_entry(self, credit, debt, name, date, comment=None): new_entry = Entry(credit, debt, name, date, comment) self._add_entry(new_entry)