Getting Error : moment.duration is not a function - node.js

I am trying to convert seconds in HH:MM:SS format. I am getting an error moment.duration is not a function.
var moment = require("moment-duration-format");
moment.duration(123, "seconds").format("hh:mm:ss");

The moment-duration-format plugin depends on moment, so you should import/require it first:
var moment = require("moment")
require("moment-duration-format");
moment.duration(123, "seconds").format("hh:mm:ss");

I tried both
import 'moment-duration-format';
and
require("moment-duration-format");
but it did not solve my problem and I was still getting TypeError: moment.duration(...).format is not a function so I took a look at https://www.npmjs.com/package/moment-duration-format to find how to correctly set it up and I found out that I have to call it and pass moment in order to make it work correctly.
import momentDurationFormatSetup from 'moment-duration-format';
momentDurationFormatSetup(moment);

Related

How do I mock a changing url in a loop?

I'm trying to mock a set of urls that change through a loop and prove out that a bad output format (not json) throws up an error. I currently have
#unittest.mock.patch("ORIG_URL", "MOCK_URL")
def test_url(self)
mock_response = "some string"
self.adapter.register_uri("GET", "MOCK_URL", json=mock_response, status_code=200)
but the original GET command is taking something of the form
let = [/path1, /path2]
for entry in let:
session.get("MOCK_URL" + entry...
so I basically need to mock something different each time it loops through but I'm unclear on how to do this. I understand where the problem is but I haven't yet found a solution. Any help would be appreciated!

How to pass RunProperties while calling the glue workflow using boto3 and python in lambda function?

My python code in lambda function:
import json
import boto3
from botocore.exceptions import ClientError
glueClient = boto3.client('glue')
default_run_properties = {'s3_path': 's3://bucketname/abc.zip'}
response = glue_client.start_workflow_run(Name="Testing",RunProperties=default_run_properties)
print(response)
I am getting error like this:
"errorMessage": "Parameter validation failed:\nUnknown parameter in input: \"RunProperties\", must be one of: Name",
"errorType": "ParamValidationError",
I also tried like this :
session = boto3.session.Session()
glue_client = session.client('glue')
But got the same error.
can anyone tell how to pass the RunProperties while calling the glue workflow to run .The RunProperties are dynamic need to be passed from lambda event.
I had the same issue and this is a bit tricky. I do not like my solution, so maybe someone else has a better idea? See here: https://github.com/boto/boto3/issues/2580
And also here: https://docs.aws.amazon.com/glue/latest/webapi/API_StartWorkflowRun.html
So, you cannot pass the parameters when starting the workflow, which is a shame in my opinion, because even the CLI suggests that: https://docs.aws.amazon.com/cli/latest/reference/glue/start-workflow-run.html
However, you can update the parameters before you start the workflow. These values are then set for everyone. If you expect any "concurrency" issues then this is not a good way to go. You need to decide, if you reset the values afterwards or just leave it to the next start of the workflow.
I start my workflows like this:
glue_client.update_workflow(
Name=SHOPS_WORKFLOW_NAME,
DefaultRunProperties={
's3_key': file_key,
'market_id': segments[0],
},
)
workflow_run_id = glue_client.start_workflow_run(
Name=SHOPS_WORKFLOW_NAME
)
This basically produces the following in the next run:
I had the same problem and asked in AWS re:Post. The problem is the old boto3 version used in Lambda. They recommended two ways to work around this issue:
Update run properties for a Job immediately after start_workflow_run:
default_run_properties = {'s3_path': 's3://bucketname/abc.zip'}
response = glue_client.start_workflow_run(Name="Testing")
updateRun = glue_client.put_workflow_run_properties(
Name = "Testing",
RunId = response['RunId'],
RunProperties = default_run_properties
)
Or you can create a lambda layer for your lambda function and include a new boto3 version there.

Twython get_retweets method gives error on number or arguments

I am trying to replicate the example shown in this SO question, and I am stumbling in what looks like a Twython bug, appreciate any insight
Here's the code:
status_id = <some_status_id>
response = twitter.get_retweets(status_id, 100)
which results in the following error
TypeError: get_retweets() takes 1 positional argument but 3 were given
I tried to run without arguments as in
response = twitter.get_retweets()
and then I get an error from Twitter saying
twython.exceptions.TwythonError: Twitter API returned a 404 (Not Found), Sorry, that page does not exist
Is this a bug?
Solved, the status_id must be passed as a named parameter
status_id = <some_status_id>
response = twitter.get_retweets(id=status_id) # 100 is already the max available

TypeError: 'numpy.ndarray' object is not callable when import a function

Hi I am getting the following error.
TypeError: 'numpy.ndarray' object is not callable
I wrote a function module by myself,like this:
from numpy import *
import operator
def creatDataset() :
group = array([[1.0,1.1],[1.0,1.0],[0,0],[0,0.1]])
labels = ['A','A','B','B']
return group,labels
then,I want to use this function in Microsoft's command window ,I've written some code, as follows:
import KNN
group,labels=KNN.creatDataset()
group()
when I input the code "group()",the error will appear.It's the first time that i describe the question and ask for help, maybe the description is not clear ,,please forgive me.
Since "group" is a numpy.array, you cannot call it like a function.
So "group()" will not work.
I assume, you want to see it's values, so you would have to use something like
"print(group)".

Groovy : why this code doesn't work ? unable to resolve class

I have this test code:
def p = [:]
p.foo = [:]
p.foo.bar = 120
p.foo.bar - 3
(p.foo.bar) + 3
why on the last statement i get a compilation error : "unable to resolve class p.foo.bar "?
Thanks for the help
Groovy version 1.8.1
OK, I think I figured it out. I ran the AST browser against your sample script (using the GroovyConsole). It would only show an output at the Conversion phase. At this phase you can see how the script is converted. The key is that the last line is converted into this:
...
((1) as p.foo.bar)
This means that, apparently, it's trying to cast or convert the 1 into a class named p.foo.bar.
You can dig a little deeper and see that the parser is parsing the statement like this:
(p.foo.bar)(+1)
Which is the same as
(p.foo.bar)1
Therefore, the parser/compiler is seeing the + as a unary + operator. And that is why you are getting the error. (The way around it it to remove the parentheses, or swap the order of the arguments!)

Resources