Showing posts with label Technical stuff. Show all posts
Showing posts with label Technical stuff. Show all posts

Why is the new MoID on Android much better?

  • 0
A new version of our Android version is out! It has many improvements but they're not visible for the user, that's why I'm writing this post!

First of all, this version is yet technologically in 2014: it means that we removed the old libraries and softwares to take only the best (for our great users, of course)! So, we moved to Gradle, we write now code with Android Studio and we make our exchange between client and server with Google Volley. From a developer side, it's day and night: the IDE is much more stable and the build process much more customizable!
But it brings also cool aspects to the users: Volley is much faster than LoopJ and also a bit more secured (I have to admit that our implementation of the old library, LoopJ, was not perfect...).

Also, the current version is so stable and reliable that it gave us the possibility to find a tiny bug in the MoID Server API, a thing which was totally impossible with the old one.

In the new version, you'll find a new Panel which demonstrates one of our new directions: gamification! It's called "Leaderboard" and you'll see there the best MoID users on the Earth (the goal is that you become #1).
To be #1 on Android, it will be a bit more complicated than on iOS because you cannot drop your ID (not yet, but it's the next step and it will come fast!) but I'm sure that the Android users are much better than the iOS users (yeah, I'm an Android user :P) so it's the perfect place to demonstrate this: invite friends, exchange contacts and be at the top!

Yes, I designed the "?", beautiful, isn't it ? ;)


Laurent Meyer
Android (what else?) Developer
@laurent_m_meyer
+Laurent Meyer

How to make a blog hit counter on Blogger (Part 2 of 2)

  • 0
So as you’ve read on this article, we now have an operational keeping the data that we’re requesting it.

Our current job is yet to link the blog to this server and retrieve the data of the server (i.e. the number of view). I must admit that I’m convinced that there is a better way to do it than the solution I'm submitting but my current knowledge in Web programmation are limiting me to this ugly but working solution. So, if you have better idea, feel free to comment this article, it would be very helpful!

First, we need to send a unique non-changing id to the server in order to associate a view count with an article. Happily, Blogger provides us this kind of data with this code:
expr:href='data:post.id'

Second, we need a way to detect if the user is on our homepage or on the article-specific page. Here also, Blogger provides us “nearly-built-in” tool with its condition and a tricky combination:

<b:if cond='data:blog.pageType == &quot;item&quot;'>
    <!-- Here is what happens if we're in article specific page -->     
    <b:else/>
         <!-- Here is what happens if we're not in article specific page -->
</b:if>

Last but not least, we need to display what the server returns and that’s the point where the solution I used is extremely dirty: I used a … <iframe>! It didn’t find any other way with JS, jQuery or whatever! If you find/know a solution, I would be very interested to know it.
Anyway, here is the code used by our blog:
<b:if cond='data:blog.pageType == &quot;item&quot;'>
          <li>
          	<iframe expr:src='&quot;http://lolobosse.pythonanywhere.com/get_count/&quot;+data:post.id' frameborder='0' height='30px' name='about' scrolling='no' width='25%'/>
          </li>
<b:else/><li>
          	<iframe expr:src='&quot;http://lolobosse.pythonanywhere.com/get_count_homepage/&quot;+data:post.id' frameborder='0' height='30px' name='about' scrolling='no' width='25%'/>
          </li>
        </b:if> 

Laurent Meyer, Android Developer
@laurent_m_meyer

How to make a blog hit counter on Blogger (Part 1 of 2)

  • 0
 --This article is a bit technical--


As you maybe have seen, we installed last week something to count the views of each article to better analyze our performance. It doesn’t like great (as I always says, honesty is something crucial!) but it counts and that’s its only purpose so it’s enough!

You were maybe laughing when you’ve seen that we’re writing an article on a dummy view counter ; so would I if I wasn’t its creator (who needed on complete day for this counter)!

But, it’s much more complicated than adding a simple widget at the end of post via WordPress or whatever! No, folks, we’re on Blogger and Blogger isn’t written in PHP and is not as flexible as WordPress or the newer platforms are!
It appeared, after a bit of research that there isn’t any Blogger variable which is counting the view per article (or that they cannot be accessed because they’re existing, as we can see on the photo).

It would be too simple to be able to take these numbers directly, isn't it?


So, without any answer to get these variables and no solution on Internet without using a closed-source third party service, I decided to build our own view counter (YOLO!).
I have to say that the only web language that I can fairly use for web development is Python associated with Flask (but if you’re using Bottle, Django or just used to Python, it is very easy to understand!).

So I wrote two basic functions: one for the article from the homepage (where they’re aren’t properly read so I do not add one view in this function) and one for the article that are requested from the article-specific page (where I’m sure they’ve clicked/read; so I’m adding 1). Here is the code:

__author__ = 'laurentmeyer'

from flask import Flask, render_template, abort, request
import pickle

app = Flask(__name__)

DictUrlViews = dict()

@app.route('/')
def test():
 return str(0)


# This view is called by each article when it is specifically called in his own page (this function adds one view).
@app.route('/get_count/')
def get_count(id):
 DictUrlViews = pickle.load(open( "savefile.txt", "rb" ))
 if id is not None:
  postId = int(id)
  views = DictUrlViews.get(postId, 0)

  # Yeah, you're right that makes no sense to add it and not to display it.
  # You'll have to invert the two lines
  DictUrlViews[postId] = views+1

  pickle.dump(DictUrlViews, open('savefile.txt', 'wb+'))

  return render_template("numberTemplate.html", number = str(DictUrlViews[postId]))
 abort(400)

# This function is called by all the articles of the main page to get their view count without adding one each time
@app.route('/get_count_homepage/')
def get_count_without_modifying(id):
  DictUrlViews = pickle.load(open( "savefile.txt", "rb" ))
  if id is not None:
  postId = int(id)
  views = DictUrlViews.get(postId, 0)
  return render_template("numberTemplate.html", number = str(views))
  abort(400)

@app.route('/set_count/')
def set_count(id):
 DictUrlViews = pickle.load(open( "savefile.txt", "rb" ))
 if id is not None:
  postId = int(id)
  views = request.args.get("views")
  if (views) is not None:
   views = int(views)
   if views >= DictUrlViews.get(postId, 0):
    DictUrlViews[postId] = views
    pickle.dump(DictUrlViews, open('savefile.txt', 'wb+'))
    return str(views)
 abort(400)


if __name__ == "__main__":
 app.run(host="0.0.0.0", debug=True)

You maybe noticed that the pickle function is useless loading on every call; the explanation is quite tricky: I’m using PythonAnywhere.com to host this code. It means that I do not have control on the server stops/restarts, which means that I need data persistence (and I find Pickle much better than SQL for so little things); and yeah, I could load only one time the pickle by calling it in the initialization function, however the initialization function is provided by PythonAnywhere (mine won’t be called when deployed, was just for local testing) and is, I think, easily modifiable but I didn’t wanna search further (coder is a lazy machine that transforms coffee into code).

So, I deployed on PythonAnywhere and I searched a way to connect to my blog…

To be continued …

Laurent Meyer, Android Developer
@laurent_m_meyer