import json
import os
import tempfile


def store(data, directory="/var/www/luke/wikipedia/graphs/"):
    try:
        json.loads(data)
    except ValueError:
        return "not-json"

    tf = tempfile.mkstemp(prefix="", dir=directory)[1]

    with open(tf, "w") as f:
        f.write(data)
    return tf

if __name__ == "__main__":
    print(store('{}'))

import json
import os
import tempfile


def store(data, directory="/var/www/luke/wikipedia/graphs/"):
    try:
        json.loads(data)
    except ValueError:
        return "not-json"

    tf = tempfile.mkstemp(prefix="", dir=directory)[1]

    with open(tf, "w") as f:
        f.write(data)
    return os.path.split(tf)[1]

if __name__ == "__main__":
    print(store('{}'))

Tweak JSON api return value to be friendlier
Tweak JSON api return value to be friendlier

  import json
  import os
  import tempfile
  
  
  def store(data, directory="/var/www/luke/wikipedia/graphs/"):
      try:
          json.loads(data)
      except ValueError:
          return "not-json"
  
      tf = tempfile.mkstemp(prefix="", dir=directory)[1]
  
      with open(tf, "w") as f:
          f.write(data)
-     return tf
+     return os.path.split(tf)[1]
  
  if __name__ == "__main__":
      print(store('{}'))
  
Tweak JSON api return value to be friendlier
## Code Before:
import json
import os
import tempfile


def store(data, directory="/var/www/luke/wikipedia/graphs/"):
    try:
        json.loads(data)
    except ValueError:
        return "not-json"

    tf = tempfile.mkstemp(prefix="", dir=directory)[1]

    with open(tf, "w") as f:
        f.write(data)
    return tf

if __name__ == "__main__":
    print(store('{}'))

## Instruction:
Tweak JSON api return value to be friendlier
## Code After:
import json
import os
import tempfile


def store(data, directory="/var/www/luke/wikipedia/graphs/"):
    try:
        json.loads(data)
    except ValueError:
        return "not-json"

    tf = tempfile.mkstemp(prefix="", dir=directory)[1]

    with open(tf, "w") as f:
        f.write(data)
    return os.path.split(tf)[1]

if __name__ == "__main__":
    print(store('{}'))
