'NoneType' object is not subscriptable pymongo - pymongo

So i am trying make it to where it checks the database and if they are in the database it sends a embed that say "User is already whitelisted" and if they aren't in the database then it adds them to the database. I keep getting the error NoneType' object is not subscriptable and i am lost at this point, any help will be useful.
#client.command(aliases=['wl'])
#commands.has_role("Database")
async def Whitelist(ctx, member: discord.Member):
member_id = member.id
result = Collection.find_one({"User Id": member_id },{ "_id": 0, "Key": 1})
KeyAdd = random.randint(23525623, 23623423426)
displayname = member.display_name
role = discord.utils.get(member.guild.roles, name="Whitelisted")
remove_role = discord.utils.get(member.guild.roles, name="Blacklisted")
AddWhitelist = {"User Id":member_id, "Display Name": displayname, "Key": f"Zelly_{KeyAdd}"}
embed2 = discord.Embed(
title = f"Whitelist Error",
color = discord.Colour(color)
)
embed2.add_field(name = "Content", value = f"{member.mention} is already whitelisted", inline = False)
embed2.set_footer(text = f'{bot_name}')
embed2.timestamp = datetime.datetime.utcnow()
embed = discord.Embed(
title = f"Whitelist Successful",
color = discord.Colour(color)
)
embed.add_field(name = "Content", value = f"Successfully whitelisted {member.mention}", inline = False)
embed.set_footer(text = f'{bot_name}')
embed.timestamp = datetime.datetime.utcnow()
embed1 = discord.Embed(
title = f"Whitelist",
color = discord.Colour(color)
)
embed1.add_field(name = "Content", value = f"You have been whitelisted for Zelly", inline = False)
embed1.add_field(name = "Key", value = result["Key"], inline = False)
embed1.set_footer(text = f'{bot_name}')
embed1.timestamp = datetime.datetime.utcnow()
if Collection.find_one({"User Id": member_id },{ "_id": 0, "Key": 1}) == None:
Added = Collection.insert_one(AddWhitelist)
await ctx.send(embed = embed)
elif Collection:
await ctx.send(embed = embed2)

Related

Add element to list on update, together with other changes in a record

I have the following initialModel,
initialModel : Model
initialModel =
{ cards =
[ { url = "Gita.jpg", card = 1, selected = False }
, { url = "Kali.jpg", card = 2, selected = False }
, { url = "Arjuna.jpg", card = 3, selected = False }
, { url = "Krishna.jpg", card = 4, selected = False }
, { url = "Manjusri.jpg", card = 5, selected = False }
, { url = "siddartha.jpg", card = 6, selected = False }
, { url = "bodhidharma2.jpg", card = 7, selected = False }
]
, selectedCards = [ "card1" ]
, activeCard = ""
}
And I have them hooked with onClick,
type Msg
= ClickedCard { url : String, id : String }
| Other
update : Msg -> Model -> Model
update msg model =
case msg of
ClickedCard data ->
{ model
| activeCard = data.id
, selectedCards = selectedCards ++ data.id -- This line is pseudo-code
}
_ ->
model
How can I make that update work? So, in the end, every click on a new card should make it on the selectedCards list.

Tarantool existing space migration

I need to add a parameter to existing space and keep the existing data.
space is created like this:
function create_user()
local space = box.schema.create_space('user', { engine = 'memtx' })
space:format({
{ name = 'user_id', type = 'unsigned' },
{ name = 'name', type = 'string' },
{ name = 'is_active', type = 'boolean' },
})
space:create_index('users_id', { type = 'TREE', parts = { 'user_id', 'name' } })
end
i need to add the following parameters
{ name = 'is_online', type = 'boolean' }
{ name = 'session_id', type = 'unsigned', is_nullable = true }
how to write the required migration script?
it's my solution
function migrate_users()
local counter = 0
local space = box.space.users
space:format({})
for _, tuple in space:pairs(
nil, {iterator=box.index.ALL}
) do
local user_tuple = tuple:totable()
user_tuple[4] = nil
user_tuple[5] = false
space:replace(user_tuple)
counter = counter + 1
if counter % 10000 == 0 then
fiber.sleep(0)
end
end
space:format({
{ name = 'user_id', type = 'unsigned' },
{ name = 'name', type = 'string' },
{ name = 'is_active', type = 'boolean' },
{ name = 'session_id', type = 'unsigned', is_nullable = true },
{ name = 'is_online', type = 'boolean' }
})
space:create_index('session_id', { type = 'TREE', unique = false, parts = { 'session_id' } })
end
it is better to use spacer immediately
https://github.com/igorcoding/tarantool-spacer

Sonos Itemtype and item content for list of podcasts and episodes

We have several podcasts, each with multiple episodes. Which itemtype should we return for the podcasts and episodes and which type should the item be?
We currently use itemtype.collection for the list of podcasts and episodes and each episode has itemtype.stream and the item is then set to streamMetadata.
This does however not allow for scrubbing.
Podcast:
var mediaData = new mediaCollection()
{
id = string.Format({0}:{1}:{2}",Prefix, moodId, moodItem.Id),
title = moodItem.Id,
itemType = itemType.collection,
onDemand = true,
liveNow = false,
language = "Norwegian",
liveNowSpecified = false,
albumArtURI = new albumArtUrl() { Value = moodItem.ImageUri.ToString(), requiresAuthentication = false, requiresAuthenticationSpecified = false}
};
Episode:
return new mediaMetadata
{
id = string.Format("{0}:{1}:{2}:{3}", Prefix, moodId, podcast.Id, episode.Publishdate.Ticks.ToString()),
title = episode.Title,
itemType = itemType.stream,
mimeType = "audio/mpeg",
onDemand = true,
onDemandSpecified = true,
language = "Norwegian",
Item = new streamMetadata()
{
currentShow = episode.Title,
logo = new albumArtUrl { Value = podcast.ImageUri.ToString(), requiresAuthentication = false, requiresAuthenticationSpecified = true },
currentHost = "Someone",
}
};
Your getMetadataResponse for podcasts should be of itemType track and should include canResume true. Check out this page for specific information and examples.

Lua Invalid HTTP request - Stripe API

I'm trying to write a module to communicate with Stripe's payment API. Already, i've come across trouble. I keep getting a response: ""Your client sent an invalid HTTP request." I've tried every possible thing I could think of..even b64..however, nothing seems to work. Any ideas?
Here is my code:
description = "test"
email = "test#email.com"
api_key = "pk_test_4PRPYs3eM4HQx0ZMBOubGjoy"-- Don't worry, this is a public test key ;)
cardNumber = "4242 4242 4242 4242"
fullName = "Test Name"
expMonth = "07"
expYear = "2016"
cvc = "432"
------------------------------------------------------------
firstCard = {["number"] = cardNumber, ["exp_month"] = expMonth, ["exp_year"] = expYear, ["cvc"] = cvc, ["name"] = fullName}
StripeNewRegister = function ()
local json = require "json"
print ("test")
newCustomer = {["email"] = email, ["description"] = description} --["card"] = firstCard}
print(newCustomer)
local function networkListener( event )
if ( event.isError ) then
print( "Network error!" )
else
print( "RESPONSE: "..event.response )
local data1 = event.response
local resp1 = json.decode(data1)
print(resp1)
local error = resp1.error
if error ~= nil then
for i = 1, #resp1.error do
print(resp1.error[i].type)
print(resp1.error[i].message)
end
end
if error == nil then
-- Print Functions
end
end
end
local key = {["Bearer"] = api_key}
local headers = {
["Authorization Bearer"] = api_key
}
local params = {}
params.headers = headers
params.body = json.encode( newCustomer )
print( "params.body: "..params.body )
network.request( "https://api.stripe.com/v1/customers", "POST", networkListener, params)
end
StripeNewRegister()

How best to traverse API information with iOS

Is there any easier way of traversing array/dictionaries without creating a lot of separate NSArrays/NSDictionaries? I know you can traverse nested dictionaries with dot notation and value at keypath, but what about when arrays are involved?
For example:
At the moment if I want to get at the object at feed.entry.link[4].href in the API result below, I have to define an array at keypath "feed.entry", then assign its first entry as a dictionary, then define an array at keypath "link" and access its fourth entry as a dictionary, and then access its value at "href".
Is this normal?
received {
encoding = "UTF-8";
feed = {
entry = (
{
author = (
{
name = {
"$t" = swdestiny;
};
uri = {
"$t" = "https://gdata.youtube.com/feeds/api/users/swdestiny";
};
}
);
category = (
{
scheme = "http://schemas.google.com/g/2005#kind";
term = "http://gdata.youtube.com/schemas/2007#video";
},
{
label = Entertainment;
scheme = "http://gdata.youtube.com/schemas/2007/categories.cat";
term = Entertainment;
},
{
scheme = "http://gdata.youtube.com/schemas/2007/keywords.cat";
term = Star;
},
{
scheme = "http://gdata.youtube.com/schemas/2007/keywords.cat";
term = Wars;
},
{
scheme = "http://gdata.youtube.com/schemas/2007/keywords.cat";
term = Episode;
},
{
scheme = "http://gdata.youtube.com/schemas/2007/keywords.cat";
term = 3;
},
{
scheme = "http://gdata.youtube.com/schemas/2007/keywords.cat";
term = Revenge;
},
{
scheme = "http://gdata.youtube.com/schemas/2007/keywords.cat";
term = of;
},
{
scheme = "http://gdata.youtube.com/schemas/2007/keywords.cat";
term = the;
},
{
scheme = "http://gdata.youtube.com/schemas/2007/keywords.cat";
term = Sith;
}
);
content = {
"$t" = "sw-destiny.net Trailer for Revenge of the Sith";
type = text;
};
"gd$comments" = {
"gd$feedLink" = {
countHint = 1567;
href = "https://gdata.youtube.com/feeds/api/videos/9kdEsZH5ohc/comments";
rel = "http://gdata.youtube.com/schemas/2007#comments";
};
};
"gd$rating" = {
average = "4.7729683";
max = 5;
min = 1;
numRaters = 1132;
rel = "http://schemas.google.com/g/2005#overall";
};
id = {
"$t" = "http://gdata.youtube.com/feeds/api/videos/9kdEsZH5ohc";
};
link = (
{
href = "https://www.youtube.com/watch?v=9kdEsZH5ohc&feature=youtube_gdata";
rel = alternate;
type = "text/html";
},
{
href = "https://gdata.youtube.com/feeds/api/videos/9kdEsZH5ohc/responses";
rel = "http://gdata.youtube.com/schemas/2007#video.responses";
type = "application/atom+xml";
},
{
href = "https://gdata.youtube.com/feeds/api/videos/9kdEsZH5ohc/related";
rel = "http://gdata.youtube.com/schemas/2007#video.related";
type = "application/atom+xml";
},
{
href = "https://m.youtube.com/details?v=9kdEsZH5ohc";
rel = "http://gdata.youtube.com/schemas/2007#mobile";
type = "text/html";
},
{
href = "https://gdata.youtube.com/feeds/api/videos/9kdEsZH5ohc";
rel = self;
type = "application/atom+xml";
}
);
"media$group" = {
"media$category" = (
{
"$t" = Entertainment;
label = Entertainment;
scheme = "http://gdata.youtube.com/schemas/2007/categories.cat";
}
);
"media$content" = (
{
duration = 151;
expression = full;
isDefault = true;
medium = video;
type = "application/x-shockwave-flash";
url = "https://www.youtube.com/v/9kdEsZH5ohc?version=3&f=videos&app=youtube_gdata";
"yt$format" = 5;
},
{
duration = 151;
expression = full;
medium = video;
type = "video/3gpp";
url = "rtsp://v2.cache4.c.youtube.com/CiILENy73wIaGQkXovmRsURH9hMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp";
"yt$format" = 1;
},
{
duration = 151;
expression = full;
medium = video;
type = "video/3gpp";
url = "rtsp://v2.cache5.c.youtube.com/CiILENy73wIaGQkXovmRsURH9hMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp";
"yt$format" = 6;
}
);
"media$description" = {
"$t" = "sw-destiny.net Trailer for Revenge of the Sith";
type = plain;
};
"media$keywords" = {
"$t" = "Star, Wars, Episode, 3, Revenge, of, the, Sith";
};
"media$player" = (
{
url = "https://www.youtube.com/watch?v=9kdEsZH5ohc&feature=youtube_gdata_player";
}
);
"media$thumbnail" = (
{
height = 360;
time = "00:01:15.500";
url = "http://i.ytimg.com/vi/9kdEsZH5ohc/0.jpg";
width = 480;
},
{
height = 90;
time = "00:00:37.750";
url = "http://i.ytimg.com/vi/9kdEsZH5ohc/1.jpg";
width = 120;
},
{
height = 90;
time = "00:01:15.500";
url = "http://i.ytimg.com/vi/9kdEsZH5ohc/2.jpg";
width = 120;
},
{
height = 90;
time = "00:01:53.250";
url = "http://i.ytimg.com/vi/9kdEsZH5ohc/3.jpg";
width = 120;
}
);
"media$title" = {
"$t" = "Star Wars Episode 3 Revenge of the Sith Trailer";
type = plain;
};
"yt$duration" = {
seconds = 151;
};
};
published = {
"$t" = "2007-05-23T03:31:54.000Z";
};
title = {
"$t" = "Star Wars Episode 3 Revenge of the Sith Trailer";
type = text;
};
updated = {
"$t" = "2012-02-20T17:14:37.000Z";
};
"yt$statistics" = {
favoriteCount = 763;
viewCount = 796719;
};
}
);
xmlns = "http://www.w3.org/2005/Atom";
"xmlns$gd" = "http://schemas.google.com/g/2005";
"xmlns$media" = "http://search.yahoo.com/mrss/";
"xmlns$yt" = "http://gdata.youtube.com/schemas/2007";
};
version = "1.0";
}