Simple question in ClientLogin using python gdata library - gdata-api

I have incorporated ClientLogin into my python application to retrieve contact list of the user , I like to know how to get the name of the user who has logged in.My code to get the names from the contact list of the user is as given below
gd_client = gdata.contacts.service.ContactsService()
gd_client.email = yemail
gd_client.password = ypass
gd_client.source = 'GoogleInc-ContactsPythonSample-1'
gd_client.ProgrammaticLogin()
query = gdata.contacts.service.ContactsQuery()
query.max_results=150
feed = gd_client.GetContactsFeed(query.ToUri())
for i, entry in enumerate(feed.entry):
#print '\n%s %s' % (ctr+i+1, entry.title.text)
na=entry.title.text
names.append(na)
Please help me to know how to get the name of the user who has logged in
Thanks
ganesh

Edit: Turns out this is only for iterating through the AppsService which will not help you. I am using GAE so for me the google.appengine.api users class takes care of all the heavy lifting for me. I will keep looking into this.
You might try the following code:
gd_client = gdata.contacts.service.ContactsService()
gd_client.email = yemail
gd_client.password = ypass
gd_client.source = 'GoogleInc-ContactsPythonSample-1'
gd_client.ProgrammaticLogin()
nick_feed = gd_client.RetrieveAllNicknames()
for nick_entry in nick_feed.entry:
print nick_entry.nickname.name
print nick_entry.login.user_name
This should work across all the gdata services. I am going to test it though and I will let you know how it goes. This information was found at this location.

Related

get_channel gives nonetype in loop

me and my friend both don't know what's going on with get_channel not working. i am currently working on a loop and need it to be in a specific channel.
#tasks.loop(seconds=2)
async def datetask():
tz = pytz.timezone('Europe/Berlin')
berlin_current_datetime = datetime.now(tz)
channel = client.get_channel(894586024607494144)
await channel.send(f"current date {berlin_current_datetime}")
datetask.start()
any help would be grateful, i looked all trough this site but nothing worked.
(seconds set to 2 just to test)
You might as well want to Read this:
https://github.com/Rapptz/discord.py/issues/2282

JXA: get containers of an element

Using JavaScript for automation in macOS, it's straightforward to get the elements of a container. But I can't figure out how to get the containers of an element.
In the Photos documentation, for example, an Album "contains mediaItems"; and a MediaItem is "contained by albums".
This works:
Application('Photos').albums[0].mediaItems()
This is what I want to write, but does not work:
Application('Photos').mediaItems[0].albums()
(resulting error:
Error: Can't get object. (-1728)
)
I've also tried to do something with the whose method, but I'm not quite sure how to write it:
Application('Photos').albums.whose({ /* what to put here? */ })
(Obviously I'd rather use the more direct route, if it exists, but if the proper way to do what I want is via whose, okay.)
I don’t think there’s a direct answer to this question. What you’re basically looking for, if I read you correctly, is, how can I use JXA to query a container based on its elements. That is, you want the answer to how to perform this AppleScript query in JavaScript:
tell application "Photos"
--get an arbitrary photo
set firstPhoto to the first media item
--get the albums that contain that photo
get the name of every album whose id of media items contains id of firstPhoto
end tell
This means going multiple levels deep, something like:
//this does not work
var firstPhoto = Application('Photos').mediaItems[0]();
var containingAlbums = Application('Photos').albums.whose({mediaItems: {_contains: firstPhoto}});
But according to the error this script generates, the albums object doesn’t even have a property called “mediaItems”.
Tantalizingly, if you were to run the following script you would see the ids of each of the albums that contains your photo:
//get a photo
var firstPhoto = Application('Photos').mediaItems[0]();
var firstPhotoId = firstPhoto.id();
albumQuery = Application('Photos').albums.mediaItems.where({id: {_equals: firstPhotoId}});
containingAlbums = []
for (var possibleAlbum of albumQuery[0]()) {
if (possibleAlbum != null) {
containingAlbums.push(possibleAlbum);
}
}
containingAlbums;
I see, for example,:
[Application("Photos").albums.byId("RLf9PUOxSLunpY5vFLLR6A").mediaItems.byId("68IM5jaiRDqIJhcKVBXo%w"),
Application("Photos").albums.byId("7QpA6wQrSEeIPyhu8xHlOw").mediaItems.byId("68IM5jaiRDqIJhcKVBXo%w"),
Application("Photos").albums.byId("SX8PbxO9S+a4%w4FvHH%Og").mediaItems.byId("68IM5jaiRDqIJhcKVBXo%w")]
But if I change the push line to containingAlbums.push(possibleAlbum.properties()); I see no property that will get the album name or even id back in any of the entries.
I asked a similar question about getting people from the same city in Contacts. The only solution I’ve been able to find is to get your media item and then loop through all albums.
//get an arbitrary photo
var firstPhoto = Application('Photos').mediaItems[0]();
var firstPhotoId = firstPhoto.id();
//loop through all albums and compile list of those that contain this photo
var containingAlbums = []
for (var possibleAlbum of Application('Photos').albums()) {
if (possibleAlbum.mediaItems.whose({id: {_equals: firstPhotoId}}).length) {
containingAlbums.push(possibleAlbum.name());
}
}
containingAlbums;
This is obviously not a satisfactory answer. I’m providing it in the hope that it may help you hack up a solution, and that someone will put up a better answer to prove me wrong.
In general, JXA support is spotty enough that if you don’t need one of its features that AppleScript doesn’t have, such as the ability to chain queries programmatically, it’s better to build the solution in AppleScript.

build app which scans barcodes and sends info to google sheet

Total newbie here but I have a question. We are trying to simplify a second hand book sale and want to build an app which allows parents to scan the barcode of books they want to sell then send this barcode, along with their name and email address (plus maybe a few other questions) to a Google Sheet.
A) is it possible to do this.
B) Any pointers to get started?
EDIT: This is for python code
a) Yes, this is very possible
b)
You are going to need a bar-code scanner that can be connected to a computer and will then, somehow, have to enable this to input into python variables.
In terms of adding to google sheets, it is very possible to do this via Googles current API - if this sounds like jumble, there are plenty of guides at there for doing this in various 'easy' ways.
Here is some basic code to help you get started: (Haven't had the time to test it, and apologies if it is not relevant as I do not know how good you are at python.)
import time
class barcode:
def init(self):
self.code = int()
def getBarcode(self):
print("Insert code to get barcode here. Assign barcode to variable: self.barcode")
if self.barcode != None or self.barcode != "":
return self.barcode()
else:
return False
def getDetails(self):
name = input("Enter your full name: ")
email = input("Enter your email address: ")
return [name, email]
def sendInfo(self, barcode, details):
name = details[0]
email = details[1]
barcode = self.barcode
print("ENTER CODE HERE TO SUBMIT TO GOOGLE SHEETS")
def main(self):
while True:
time.sleep(1)
barcode = self.getBarcode()
if barcode != False:
details = self.getDetails()
self.sendInfo(barcode, details)
If you need more help, or are worse at python than I expect, feel free to comment below.
Extra:
- Haven't had the chance to check it out or check its full relevance however this may help you: https://gist.github.com/JoachimL/1629f701fdb38427091710fc0caef67d

Youtube API V3 Insert Comment Issue

I'm essentially using the sample code provided by the docs here but I'm getting an error that reads ArgumentError - unknown keyword: snippet. Does anyone else have this problem as well? I'm not sure if this is a valid bug but intuitively the sample code they provide should work right?
properties = {
'snippet.parentId': '123',
'snippet.textOriginal': message
}
resource = create_resource(properties)
response = service.insert_comment('snippet', resource)
Upon digging through the actual library, I discovered that the way to pass in the snippet part is as follows:
snippet = Google::Apis::YoutubeV3::CommentSnippet.new(parent_id: parent_id, text_original: message)
comment = Google::Apis::YoutubeV3::Comment.new(snippet: snippet)
response = service.insert_comment('snippet', comment)
Hope this saves someone from a huge headache of having to chase through their docs

Creating barcode images

I need to send emails out to several thousand customers with a unique barcode present so they can redeem it either instore or online.
We have a list of coupon/barcode codes to use and have a way to dynamically pull these codes into the email so a customer will see a unique code. The problem is I need to somehow generate several thousand barcode images that are created using the unique codes. How can I solve this?
This would be perfect if our email marketing company had this functionality but unfortunately they don't:
http://www.emaildirect.com/blog/2011/11/create-unique-barcodes-with-emaildirect/
Any help would be greatly appreciated.
I have found my answer!
By using the barcode generator www.barcodesinc.com I generated a URL and input this into my email.
Eg: http://www.barcodesinc.com/generator/image.php?code=999999999&style=197&type=C128B&width=200&height=50&xres=1&font=3
I then changed the 999999999 in the URL to my conditional code to change to the specific code for that person and also bring back the barcode image for that code too!
I have found my answer!
By using the barcode generator www.barcodesinc.com I generated a URL and input this into my email.
Eg: http://www.barcodesinc.com/generator/image.php?code=999999999&style=197&type=C128B&width=200&height=50&xres=1&font=3
I then changed the 999999999 in the URL to my conditional code to change to the specific code for that person and also bring back the barcode image for that code too!
<img src="http://qrfree.kaywa.com/?s=8&d=your+text+here" alt="QRCode"/>
OR
http://qrfree.kaywa.com/?s=8&d=your+text+here
I'm no expert on this and haven't touched html but you could serialize each image and follow this example that has some sample code on QR code given a string.
Imports ThoughtWorks.QRCode.Codec
Dim objQRCode As QRCodeEncoder = New QRCodeEncoder()
Dim imgImage As Image
Dim objBitmap As Bitmap
objQRCode.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE
objQRCode.QRCodeScale = 2
objQRCode.QRCodeVersion = 5
objQRCode.QRCodeErrorCorrect = ThoughtWorks.QRCode.Codec.QRCodeEncoder.ERROR_CORRECTION.L
imgImage = objQRCode.Encode("Test Data")
objBitmap = New Bitmap(imgImage)
objBitmap.Save("C:\QRCode.jpg")
Hi Try getting in touch with http://www.linktagger.com and ask if they can help. They provide Enterprise type services for the city where I live on maps and bus terminals so it might help you.
Here is an working example to generate barcode for the array of barcodes.We can
retrieve thousands of barcodes from csv file using pandas as well.
This example calls API and save the response in image(.png format) obtained as response from API call.
import shutil
import requests
data = [11111111111, 22222222222222222, 33333333333333, 4444444444444]
url = 'https://www.barcodesinc.com/generator_files/' + 'image.php?'
for d in data:
params = {
'code': d,
'style': '197',
'type': 'C128B',
'width': '200',
'height': '50',
'xres': '1',
'font': '3',
}
response = requests.get(url, params, stream=True)
with open('image-%s.png' % d, 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
del response

Resources