def __get_item_data(self, item): """ gets information out of <item>..</item> @return: output, note, properties, tags variables for orgwriter.append_org_subitem """ try: #logging.debug(item) properties = OrgProperties() guid = item['id'] if not guid: logging.error("got no id") unformatted_link = item['link'] short_link = OrgFormat.link(unformatted_link, "link") # if we found a url in title # then append the url in front of subject if re.search("http[s]?://", item['title']) != None: output = short_link + ": " + item['title'] else: output = OrgFormat.link(unformatted_link, item['title']) note = item['description'] # converting updated_parsed UTC --> LOCALTIME timestamp = OrgFormat.datetime( time.localtime(calendar.timegm(item['updated_parsed']))) properties.add("guid", guid) except KeyError: logging.error("input is not a RSS 2.0") sys.exit(1) tags = [] dont_parse = [ 'title', 'description', 'updated', 'summary', 'updated_parsed', 'link', 'links' ] for i in item: logging.debug(i) if i not in dont_parse: if (type(i) == unicode or type(i) == str) and \ type(item[i]) == unicode and item[i] != "": if i == "id": i = "guid" properties.add(i, item[i]) else: if i == "tags": for tag in item[i]: logging.debug("found tag: %s", tag['term']) tags.append(tag['term']) return output, note, properties, tags, timestamp
def __get_item_data(self, item): """ gets information out of <item>..</item> @return: output, note, properties, tags variables for orgwriter.append_org_subitem """ try: #logging.debug(item) properties = OrgProperties() guid = item['id'] if not guid: logging.error("got no id") unformatted_link = item['link'] short_link = OrgFormat.link(unformatted_link, "link") # if we found a url in title # then append the url in front of subject if re.search("http[s]?://", item['title']) != None: output = short_link + ": " + item['title'] else: output = OrgFormat.link(unformatted_link, item['title']) note = item['description'] # converting updated_parsed UTC --> LOCALTIME timestamp = OrgFormat.datetime( time.localtime(calendar.timegm(item['updated_parsed']))) properties.add("guid", guid) except KeyError: logging.error("input is not a RSS 2.0") sys.exit(1) tags = [] dont_parse = ['title', 'description', 'updated', 'summary', 'updated_parsed', 'link', 'links'] for i in item: logging.debug(i) if i not in dont_parse: if (type(i) == unicode or type(i) == str) and \ type(item[i]) == unicode and item[i] != "": if i == "id": i = "guid" properties.add(i, item[i]) else: if i == "tags": for tag in item[i]: logging.debug("found tag: %s", tag['term']) tags.append(tag['term']) return output, note, properties, tags, timestamp
def __handle_file(self, photo_file, filename): """ checks if file is an image, try to get exif data and write to org file """ logging.debug("handling file %s", filename) # check if file is an image: if imghdr.what(filename) != None: datetime = get_exif_datetime(filename) if datetime == None: logging.debug("skipping: %s has no EXIF information", filename) else: try: datetime = time.strptime(datetime, "%Y:%m:%d %H:%M:%S") timestamp = OrgFormat.datetime(datetime) output = OrgFormat.link(filename, photo_file) properties = OrgProperties(photo_file + timestamp) self._writer.write_org_subitem(timestamp=timestamp, output=output, properties=properties) except ValueError, e: logging.warning("skipping: Could not parse " + \ "timestamp for %s : %s", filename, e)
def __parse_and_write_file(self, file, link): """ Parses the date+time and writes entry to outputfile @param file: filename @param link: path """ if TIMESTAMP_REGEX.match(file): # if we found a timestamp too,take hours,min # and optionally seconds from this timestamp timestamp = TIMESTAMP_REGEX.match(file).group() orgdate = OrgFormat.strdatetimeiso8601(timestamp) logging.debug("found timestamp: " + orgdate) else: datestamp = DATESTAMP_REGEX.match(file).group() orgdate = OrgFormat.strdate(datestamp) orgdate_time_tupel = OrgFormat.datetupeliso8601(datestamp) file_datetime = time.localtime(os.path.getmtime(link)) # check if the file - time information matches year,month,day, # then update time if file_datetime.tm_year == orgdate_time_tupel.tm_year and \ file_datetime.tm_mon == orgdate_time_tupel.tm_mon and \ file_datetime.tm_mday == orgdate_time_tupel.tm_mday: logging.debug("found a time in file.setting %s-->%s", orgdate, OrgFormat.date(file_datetime, True)) orgdate = OrgFormat.date(file_datetime, True) # write entry to org file output = OrgFormat.link(link=link, description=file) # we need optional data for hashing due it can be, that more # than one file have the same timestamp properties = OrgProperties(data_for_hashing=output) self._writer.write_org_subitem(timestamp=orgdate, output=output, properties=properties)
def __handle_file(self, photo_file, filename): """ checks if file is an image, try to get exif data and write to org file """ logging.debug("handling file %s", filename) # check if file is an image: if imghdr.what(filename) != None: datetime = get_exif_datetime(filename) if datetime == None: logging.debug("skipping: %s has no EXIF information", filename) else: try: datetime = time.strptime(datetime, "%Y:%m:%d %H:%M:%S") timestamp = OrgFormat.datetime(datetime) output = OrgFormat.link(filename, photo_file) properties = OrgProperties(photo_file + timestamp) self._writer.write_org_subitem(timestamp=timestamp, output=output, properties=properties) except ValueError, e: logging.warning("skipping: Could not parse " + \ "timestamp for %s : %s", filename, e)
def __parse_and_write_file(self, file, link): """ Parses the date+time and writes entry to outputfile @param file: filename @param link: path """ if TIMESTAMP_REGEX.match(file): # if we found a timestamp too,take hours,min # and optionally seconds from this timestamp timestamp = TIMESTAMP_REGEX.match(file).group() orgdate = OrgFormat.strdatetimeiso8601(timestamp) logging.debug("found timestamp: " + orgdate) else: datestamp = DATESTAMP_REGEX.match(file).group() orgdate = OrgFormat.strdate(datestamp) orgdate_time_tupel = OrgFormat.datetupeliso8601(datestamp) file_datetime = time.localtime(os.path.getmtime(link)) # check if the file - time information matches year,month,day, # then update time if file_datetime.tm_year == orgdate_time_tupel.tm_year and \ file_datetime.tm_mon == orgdate_time_tupel.tm_mon and \ file_datetime.tm_mday == orgdate_time_tupel.tm_mday: logging.debug("found a time in file.setting %s-->%s", orgdate, OrgFormat.date(file_datetime, True)) orgdate = OrgFormat.date(file_datetime, True) # write entry to org file output = OrgFormat.link(link=link, description=file) # we need optional data for hashing due it can be, that more # than one file have the same timestamp properties = OrgProperties(data_for_hashing=output) self._writer.write_org_subitem(timestamp=orgdate, output=output, properties=properties)
def __write_file(self, file, link, timestamp): """ write entry to org file (omit replacement of spaces in file names) """ output = OrgFormat.link(link=link, description=file, replacespaces=False) # we need optional data for hashing due it can be, that more # than one file have the same timestamp properties = OrgProperties(data_for_hashing=output) self._writer.write_org_subitem(timestamp=timestamp, output=output, properties=properties)
def __write(self): """ write attributes to writer (make an org_sub_item) """ logging.debug("msg:%s", self.__msg) #getting tags if self.__attrtags: tags = self.__attrtags if self.__split: tags = tags.split(self.__split) else: tags = tags.split(' ') tags = tags[1:] elif self.__taging: tags = self.__taging if self.__split: tags = tags.split(self.__split) else: tags = tags.split(' ') else: tags = [] for item in tags: if item == '': tags.remove(item) #getting output if not self.__attroutput: output = "%s: %s" % (self.__author, self.__msg) else: output = self.__attroutput part = output.split(" ") output = "" for item in part: if re.search("http[s]?://", item) != None: unformatted_link = item short_link = OrgFormat.link(unformatted_link, "link") output = output + " " + short_link + ": " + item else: output = output + " " + item output = output[1:] #getting properties if not self.__attrproperties: properties = OrgProperties(data_for_hashing=self.__author \ + self.__msg + self.__date) else: properties = OrgProperties(data_for_hashing=self.__attrproperties) #getting notes if self.__attrnote: notes = self.__attrnote elif self.__notes: notes = self.__notes else: notes = "" if notes: parts = notes.split(" ") notes = "" for item in parts: if re.search("http[s]?://", item) != None: unformatted_link = item short_link = OrgFormat.link(unformatted_link, "link") notes = notes + " " + short_link + ": " + item else: notes = notes + " " + item notes = notes[1:] #prepare for most time formats + getting timestamp if self.__attrtime: self.__date = self.attrtime try: if (self.__time == 'YYYYMMDD' or self.__time == 'YYYY' or self.__time == 'YYYYMMDDTHHMMSSZ' or self.__time == 'YYYYMMDDTHHMMSST'): timestamp = OrgFormat.datetime( OrgFormat.datetupelutctimestamp( self.__date)) elif (self.__time == ('YYYY-MM-DD')): timestamp = OrgFormat.datetime( OrgFormat.datetupeliso8601( self.__date)) elif (self.__time == 'YYYY-MM-DDTHH.MM.SS' or self.__time == 'YYYY-MM-DDTHH.MM'): timestamp = OrgFormat.datetime( OrgFormat.datetimetupeliso8601( self.__date)) elif (self.__time == 'timetuple'): time_tupel = time.localtime(time.mktime( parsedate(self.__date))) timestamp = OrgFormat.datetime(time_tupel) except: logging.debug("Write functione @timestamp timestamp=%s", self.__date) logging.error("A timestamp problem occured") sys.exit(2) self._writer.write_org_subitem(output=output, timestamp=timestamp, note=notes, tags=tags, properties=properties)
def __read_store_and_write(self, store_file): """ Reads needed infos of .tagstore/store.tgs, parse the infos, write to outputfile @param store_file: string contains the input from store.tgs """ parser = SafeConfigParser() parser.read(store_file) sections = parser.sections() options = parser.options(sections[1]) for i in range(0, len(options), 3): filename = options[i].split('\\') filename = filename[0] tags = parser.get(sections[1], options[i]) timestamp = parser.get(sections[1], options[i + 1]) category = parser.get(sections[1], options[i + 2]) tags = tags.replace('"', '') tags = tags.replace(' ', '_') tags = tags.replace(':', '_') category = category.replace('"', '') category = category.replace(' ', '_') category = category.replace(':', '_') tags = tags.split(",") category = category.split(",") timestamp = timestamp[0:16] tagstoring = [] tagstoring.extend(tags) tagstoring.extend(category) x = 0 while x < len(tagstoring): if tagstoring[x] == '': tagstoring.pop(x) else: y = x + 1 while y < len(tagstoring): if tagstoring[x] == tagstoring[y]: tagstoring.pop(y) else: y = y + 1 x = x + 1 unformatted_link = self.__path + "/" + filename short_link = OrgFormat.link(unformatted_link, "link") link = ":FILEPATH: " + short_link timestamp = OrgFormat.strdatetime(timestamp) output = filename.decode("utf-8", "replace") data_for_hashing = output.decode("utf-8", "replace") properties = OrgProperties(data_for_hashing=data_for_hashing) self._writer.write_org_subitem(timestamp=timestamp, output=output, note=link, tags=tagstoring, properties=properties)