Building a REST python client for a server that expects timestamps to be passed in this format:
2018-05-17T06:57:16.300Z
When writing clients for this server, it is easy to get this kind of timestamp in both Java (serializing an Instant with Jackson) and Javascript (using new Date().toISOString()).
However, I couldn't find a standard way of getting this sort of timestamp in Python using the standard library or the common packages for handling time (Arrow, Pendulum).
All the solutions I found online required manually defining the string format, or (even worse) doing string manipulations to add the Z at the end of the timestamp and put the T in place.
So - is there a standard way of getting current UTC time with the Z notation in Python?
Found an answer. Using Pendulum, one can do the following:
pendulum.now(pendulum.UTC).to_iso8601_string()
Related
Is there a way to directly get script representation of a Cairo drawing without saving the script to a file in C++?
I'm trying to get the script in order to do test by comparing scripts. Have tried cairo_script_create_for_stream but using streaming seems a little bit overkill for my use case.
I'm assuming this can't be done easily but atm I've written for loops in python that take in multiple files from a folder and runs them against an executable to convert them into a readable format. Problem is, the number of files will be different almost every time I run the script. The whole process takes a while so a progress bar would be nice. I've been trying tqdm, progress, etc. modules, but they all seem to work based on a fixed number of iterations, which doesn't work for me.
Basically, is there any possible way to easily implement a progress bar which either calculates progress based on how long the process will take to perform the conversions, or based on how many there are to convert?
Though having said this, for one part of the code, instead of taking in files, it was easier to run a powershell script in cmd through python to keep it part of the same code. This script iterates through many many files and outputs 1 file. Again, is there a way to monitor the progress of this in python, even though in python the code is just running something in cmd?
Try PyProg! PyProg is an open-source library for Python to create super customizable progress indicators & bars.
It is currently at version 1.0.2; it is hosted on Github and available on PyPI (Links down below). It is compatible with Python 3 and 2.
I actually made PyProg because I needed a simple but super customizable progress bar library. And I made it super flexible as well, so you can use set_total(<total>) to set the total number of files you need to convert and use set_stat(<status>) to set the current progress, and it will calculate the percentage for you!
You can easily install it with: pip install pyprog. Some examples of using it is on the Github page for this project.
PyProg Github: https://github.com/Bill13579/pyprog
PyPI: https://pypi.python.org/pypi/pyprog/
I am writing a program to real time convert between AMR-nb and ILBC. As I would like to convert it in real time, I don't want any files to be generated. calling shell by STDIN/STDOUT/piping or call program library (JAVA/node.js) directly are preferred.
I found that ffmpeg/sox do not support both formats. What ways do you think I can use to convert between them?
How to read excel(2007+ xlsx) sheet using actionscript(AIR)?
as3xls
An Actionscript 3 library for reading and writing Excel files. Currently reading numbers, text, and formulas from Excel version 2.0-2003 and writing numbers, text, and dates to Excel 2.0 is supported. No server-side help is needed.
SUPPORT INFORMATION
Documentation and samples are at http://code.google.com/p/as3xls/
I wrote this: https://github.com/childoftv/as3-xlsx-reader I'd love to know if it helps
Do you have any idea how... Inefficient this is?
Excel uses a complex setup for files, and unless you want to write a full-scale parser for its spreadsheets (which, believe me, will be difficult, alone to figure out what the format chars do), you'd be better off finding another solution.
Say, using a "save to XML" option would make your job a few thousand times easier, without exaggeration. AS3 has no native support for Excel, there is no real point for it to have such. But it has great integrated methods for working with XML.
If possible, save the Excel files to XML and parse those.
Better still, use databases, and parse them as XML through PHP.
I did a search and came up with this: http://code.google.com/p/php-excel-reader/
Once you've got it in PHP, passing it on to Flash is no problem at all. I'd recommend turning it into straight arrays of objects and converting it to AMF3 via Zend_Amf, AMFPHP or WebOrb, whichever one you're most comfortable with. You can then create tables, manipulate the data or whatever you like. It'd also be a lot faster and lighter than using XML.
PK
I took a look at the xlsx breakdown and it would take me 1 week to write an xlsx writer that could do basic formatting and formulas. I've only spent 1 hour perusing through the directories in an xlsx file and all you'd have to do is create the same directory structure...mostly cut and paste some strings..and then zip it and call it xlsx.
I tried this theory by manually making an xlsx file using 7zip. I downloaded childoftv's reader and, though I don't need the reader, the package includes a few zip/unzip classes that would prove helpful for anyone who wants to make a xlsx writer.
Long story short, the setup isn't complex, somebody just has to take a week out of their busy schedule to do it. I need this functionality so if nobody's done it yet, then I'll have to. Hopefully my search will find something better than a forum where the general consensus is "it's too hard, give up."
In our business, we require to log every request/response which coming to our server.
At this time being, we are using xml as standard implementation.
Log files are used if we need to debug/trace some error.
I am kind of curious if we switch to protocol buffers, since it is binary, what will be the best way to log request/response to file?
For example:
FileOutputStream output = new FileOutputStream("\\files\log.txt");
request.build().writeTo(outout);
For anyone who has used protocol buffers in your application, how do you log your request/response, just in case we need it for debugging purpose?
TL;DR: write debugging logs in text, write long-term logs in binary.
There are at least two ways you can do this logging (and maybe, in fact, you should do both):
Writing your logs in text format. This is good for debugging and quickly checking for problems with your eyes.
Writing your logs in binary format - this will make future analysis much quicker since you can load the data using same protocol buffers code and do all kinds of things on them.
Quite honestly, this is more or less the way this is done at the place this technology came from.
We use the ShortDebugString() method on the C++ object to write down a human-readable version of all incoming and outgoing messages to a text-file. ShortDebugString() returns a one-line version of the same string returned by the toString() method in Java. Not sure how easy it is to accomplish the same thing in Java.
If you have competing needs for logging and performance then I suppose you could dump your binary data to the file as-is, with perhaps each record preceded by a tag containing a timestamp and a length value so you'll know where this particular bit of data ends. But I hasten to admit this is very ugly. You will need to write a utility to read and analyze this file, and will be helpless without that utility.
A more reasonable solution would be to dump your binary data in text form. I'm thinking of "lines" of text, again starting with whatever tagging information you find relevant, followed by some length information in decimal or hex, followed by as many hex bytes as needed to dump your buffer - thus you could end up with some fairly long lines. But since the file is line structured, you can use text-oriented tools (an editor in the simplest case) to work with it. Hex dumping essentially means you are using two bytes in the log to represent one byte of data (plus a bit of overhead). Heh, disk space is cheap these days.
If those binary buffers have a fairly consistent structure, you could even break out and label fields (or something like that) so your data becomes a little more human readable and, more importantly, better searchable. Of course it's up to you how much effort you want to sink into making your log records look pretty; but the time spent here may well pay off a little later in analysis.
If you've non-ASCII character strings in your messages, simply logging them by using implicit or explicit call to toString would escape the characters.
"오늘은 무슨 요일입니까?" becomes "\354\230\244\353\212\230\354\235\200 \353\254\264\354\212\250 \354\232\224\354\235\274\354\236\205\353\213\210\352\271\214?"
If you want to retain the non-ASCII characters, use TextFormat.printer().escapingNonAscii(false).printToString(message).
See this answer for more details.