How do I create embedded field via Pyorient OGM - mongodb

I am considering to migrate from MongoDB to OrientDB, as my data is a graph, but I do require features of document from MongoDB, especially the embedded document.
I was able to define the scheme in OrientDB's web client, however it was too slow, when your model is complex and cannot be reused for future. Thus I want to use pyorient.ogm to define the schema.
However, the documentation of pyorient or OrientDB is terrible. It doesn't provide any document or examples of defining embedded via pyorient.
For example, I have the following schema definition via pyorient.ogm.
class Entity(Node):
class Contact(object):
name = String(nullable=False)
phone = String(default='')
email = String(default='')
website = String(default='')
meet = String(default='')
name = String(nullable=False, indexed=True)
abstract = String(nullable=False)
nick = String(default='', indexed=True)
logo = String(default='')
type = Integer(mandatory=True, indexed=True)
tag = EmbeddedList(default=[], linked_to=String(), indexed=True)
introduction = String(default='')
reference = String(default='', indexed=True)
contact = EmbeddedMap(linked_to=Contact())
def init_database(name):
graph = Graph(Config.from_url('plocal://us.zhqiang.org:2424/{}'.format(name), 'root', 'Button.2018'))
graph.drop()
graph = Graph(Config.from_url('plocal://us.zhqiang.org:2424/{}'.format(name), 'root', 'Button.2018'))
graph.clear_registry()
graph.create_all(Node.registry)
graph.create_all(Relationship.registry)
if __name__ == '__main__':
init_database('data')
This code runs successfully, but after examine the schema in the web client, I find it doesn't handle the embedded very well.
Expected:
- A generic class should be created for Contact
- The tag should be shown as EMBEDDEDLIST with link_type=String.
- the contact should be shown as EMBEDDEDLIST with link_class=Contact.
Actual result:
- No generic class was created for Contact
- The tag is shown as EMBEDDEDLIST but link_type is empty.
- the contact is shown as EMBEDDEDLIST but link_class is empty.

Related

Premium search API, use of retweets_of and from function

I am using TwitterAPI in python3 for premium search to find archived tweets that are retweeted by user1 from user2 with specific keywords. After some suggestions, I have used https://developer.twitter.com/en/docs/tweets/rules-and-filtering/overview/operators-by-product and https://github.com/geduldig/TwitterAPI to make this code, but when I run the code I am not getting any output or error message.
The code works fine when I am not using the retweets_of and from operators, but these are the rules I want to use to get my data.
I know my code shows a premium Sandbox search, but I will upgrade it to premium Full Archive search when I have the right code.
from TwitterAPI import TwitterAPI
#Keys and Tokens from Twitter Developer
consumer_key = "xxxxxxxxxxxxx"
consumer_secret = "xxxxxxxxxxxxxxxxxxx"
access_token = "xxxxxxxxxxxxxxxxxxx"
access_token_secret = "xxxxxxxxxxxxxxxxx"
PRODUCT = '30day'
LABEL = 'MyLABELname'
api = TwitterAPI(consumer_key, consumer_secret, access_token, access_token_secret)
r = api.request('tweets/search/%s/:%s' % (PRODUCT, LABEL),
{'query':'retweets_of:user.Tesla from:user.elonmusk Supercharger battery'})
for item in r:
print (item['text'] if 'text' in item else item)
Does someone know what the problem is with my code or is there any other way to use the retweets_of and from operators for a premium search. Is it also possible to add a count operator to my code so it will give numbers as output and not all of the tweets in writing?
You should omit "user." in your query.
Also, by specifying "Supercharger battery", which is perfectly fine, you require both in the search results. However, if you require only either word to be present, you would use "Supercharger OR battery".
Finally, to specify a larger number of results, use the maxResults parameter (10 to 100).
Here is your example with all of the above:
r = api.request('tweets/search/%s/:%s' % (PRODUCT, LABEL),
{'query':'retweets_of:Tesla from:elonmusk Supercharger OR battery',
'maxResults':100})
Twitter's Premium Search doc may be helpful: https://developer.twitter.com/en/docs/tweets/search/api-reference/premium-search.html

How to use Electroserver's embedded Derby Database in AS3?

I am trying to create an online multiplayer game with electroserver like here:
http://gamesfromjames.weebly.com/pickit.html
I was looking at the source code from electrotank. Unfortunately, I cannot compile it in flash CS6 because the document class is in mxml.(if someone can help me figure out how to test these examples in pure as3 that would be great) I did find these two functions in hte mxml class:
/**
* Increases your rank by the amount specified by sending a properly formatted message to the plugin.
*/
private function addToRankClicked():void {
var ipr:PluginRequest = new PluginRequest();
ipr.pluginName = "DatabasePlugin";
var esob:EsObject = new EsObject();
esob.setString(PluginConstants.ACTION, PluginConstants.TAG_ADD_TO_RANK);
esob.setInteger(PluginConstants.TAG_ADD_TO_RANK, rankDeltaStepper.value);
ipr.parameters = esob;
_es.engine.send(ipr)
}
/**
* Loads your rank from the database by asking the plugin for it.
*/
private function getRank():void {
var ipr:PluginRequest = new PluginRequest();
ipr.pluginName = "DatabasePlugin";
ipr.zoneId = -1;
ipr.roomId = -1;
var esob:EsObject = new EsObject();
esob.setString(PluginConstants.ACTION, PluginConstants.TAG_GET_RANK);
ipr.parameters = esob;
_es.engine.send(ipr)
}
Is this all that is needed to put things into the database and take things out or am I missing something?
If I was going to try to save the chat history and show it every time a user enters the chat room, how would I go about doing it with electroserver's derby database?
Thanks!
PS If Teresa is out there reading this you should reccommend they make an electroserver tag for this forum. Im not level 1500 yet..
The database parts of that example are all done in the extension, i.e the Java classes. The two functions you quote are simply the client sending a plugin request to either ask for the user's current rank, or to increment that rank.
How familiar are you with SQL of any kind? Derby is about the same as MySQL, etc. You will need to design a database table for storing the data you want to persist, then implement Java and SQL similar to the example's code for storing the user's rank and updating it.

accessing a variable outside a Requesthandler

i'm using CSS3 accordion effect, and i want to detect if a hacker will
make a script to make a parallel request; ie:
i've a login form and a registration form in the same page, but only
one is visible because there is a CSS3: to access the page, the user
agent must be HTML5 compatible.
the tip i use is:
class Register(tornado.web.RequestHandler):
def post(self):
tt = self.get_argument("_xsrf") + str(time.time())
rtime = float(tt.replace(self.get_argument("_xsrf"), ""))
print rtime
class LoginHandler(BaseHandler):
def post(self):
tt = self.get_argument("_xsrf") + str(time.time())
ltime = float(tt.replace(self.get_argument("_xsrf"), ""))
print ltime
i've used the xsrf variable because it's unique for every user, to
avoid making the server think that the request is coming from the same
machine.
now what i want: how to make the difference between time values:
abs(ltime - rtime) ; mean, how do i access to rtime outside the class,
i just know how to access the value outside the method, i want to make
this operation to detect if the value is small, then the user is using
a script to make a parallel request to kill the server!
in other words (for general python users)
if i have:
class Product:
def info(self):
self.price = 1000
def show(self):
print self.price
>>> car = Product()
>>> car.info()
>>> car.show()
1000
but what if i've another
class User:
pass
then how do make a method that prints me the self.price, i've tried
inheritance, but got error: AttributeError: User instance has no
attribute 'price', so only methods are passed, not attributs?
It sounds like you need to understand Model objects and patterns that use persistant storage of data. tornado.web.RequestHandler and any object that you subclass from it only exists for the duration of your request. From when the URL is received on the server to when data is sent back to the browser via a self.write() or self.finish().
I would recommend you look at some of the Django or Flask tutorials for some basic ideas of how to build a MVC application in Python (There is no Tornado Tutorials that cover this that I know of).

Modifying native module to work with other tables

I want to modify a native joomla module that display articles of a category. I want it to display articles of an other prefix tables (both joomla website are on the same server).
Notice that I already looked at available extension but none of them would fit.
I tried to modify the helper.php of the native joomla module
tables, by changing the
$com_path =
but i am getting aFatal error.
Native code:
$com_path = JPATH_SITE.'/components/com_content/';
My try :
$com_path = '/homez.420/kmxsiksf/rsc/components/com_content/helpers/route.php
To use an external database (even if it's on your server) in Joomla extensions, the proper way would be to set some options before retrieving the JDatabase-object.
Create a helperclass to handle your external db, and in every method that uses the DB-object you simply set the options of your external db before retrieving the object:
$option = array();
$option['driver']   = 'mysql';
$option['host']     = 'localhost';    // In your case probably localhost
$option['user']     = 'dbusername';       // User for database authentication $option['password'] = 'badpass12345';   // Password for database authentication $option['database'] = 'bigdatabase';      // Database name
$option['prefix']   = 'abc_';             // Database prefix (may be empty)
$db = & JDatabase::getInstance( $option );
You are now able to use your external database the same way as you would with your regular db.

How to create project issue in Project Workspace programmatically?

I would like to be able to create project issue automatically. The aim is to create new issue based on received email.
I looked at ProjectWSSInfoDataSet, which is supposed to have reference to issue list (according to "PSI Methods and DataSets for Project Workspaces" at http://msdn.microsoft.com/en-us/library/aa495198(office.12).aspx). Indeed, ProjectWSSInfoDataSet XML schema contains PROJECT_ISSUES_URL field, but if it is just the url then it is not much usefull for me.
Has anyone did something similar? (Or possibly with project risks or deliverables.)
I think have to do it with the SharePoint Webservices. Find the list in the specified web and update it.
I recommend the SharePoint 2010 Client Object Model to do this:
//Use SP2010 Client Object Model to update the list
ClientContext SPContext = new ClientContext(wssUrl);
//Get list by name
string listname = "issues";
var query = SPContext.LoadQuery(SPContext.Web.Lists.Where(l => l.Title == listname));
SPContext.ExecuteQuery();
List myIssueList = query.FirstOrDefault();
//Add an item
ListItemCreationInformation nItem = new ListItemCreationInformation();
nItem.LeafName = "Blubb..";
myIssueList.AddItem(nItem);
SPContext.ExecuteQuery();
If you wan't to get the Workspace Url via the Project Id, you can do this by WSSInterop Webservice of the Project Server:
//Use WssInterop Webservice to get the Workspace URL
WssInteropSoapClient wssinteropSvc = new WssInteropSoapClient();
Guid prjGuid = new Guid("30937680-39FA-4685-A087-90C73376B2BE");
ProjectWSSInfoDataSet wssData = wssinteropSvc.ReadWssData(prjGuid);
string wssUrl = wssData.ProjWssInfo[0].PROJECT_WORKSPACE_URL;
I don't know if the code will compile, but it should work like this.
Regards Florian

Resources