I want to retrieve output of the next command (where p4 is standard perforce client):
p4 diff2 //depot/...#1 //depot/...#2
In terminal it is producing something like this:
==== //depot/bin/build.sh#1 (xtext) - //depot/bin/build.sh#2 (xtext) ==== content
1a2
> #added something 2
9c10
< fi---
> fi
==== //depot/bin/README#1 - <none> ===
==== //depot/bin/status_ok#1 - <none> ===
Let's assume that I have next script in python:
from P4 import P4
p4 = P4()
p4.port = "1818"
p4.host = "localhost"
p4.user = "psih"
p4.client = "build_verificator_ws2"
p4.connect()
changes = p4.run_diff2("//depot/...#1", "//depot/...#2")
print changes
p4.disconnect()
After execution python script I will receive something like that:
[{'status': 'content', 'depotFile2': '//depot/bin/build.sh', 'rev': '1', 'rev2': '2', 'type': 'xtext', 'depotFile': '//depot/bin/build.sh', 'type2': 'xtext'}, {'status': 'left only', 'type': 'text', 'rev': '1', 'depotFile': '//depot/bin/README'}, {'status': 'left only', 'type': 'text', 'rev': '1', 'depotFile': '//depot/bin/status_ok'}]
List of files in depot with revisions but no diffs.
Any suggestions?
The answer is in using a non-tagged response:
changes = p4.run_diff2("//depot/...#1", "//depot/...#2", tagged=False)
Related
I am trying to extract table information from pdf using Camelot-py library. Initially using stream function like this:
import camelot
tables = camelot.read_pdf('sample.pdf', flavor='stream', pages='1', columns=['110,400'], split_text=True, row_tol=10)
tables.export('ipc_export.csv', f='csv', compress=True)
tables[0]
tables[0].parsing_report
tables[0].to_csv('ipc_export.csv')
tables[0].df
However could not get the desired outcome, even after adjusting the columns value.
Then I switched to lattice flavor. It can now determine the column accurately, however due to the nature that the pdf source does not separate rows using lines, the whole table content are extracted on one row.
Below using lattice:
import camelot
tables = camelot.read_pdf('sample_camelot_extract.pdf', flavor='lattice', pages='1')
tables.export('ipc_export.csv', f='csv', compress=True)
tables[0]
tables[0].parsing_report
tables[0].to_csv('ipc_export.csv')
tables[0].df
source file snapshot
The logic that I want to implement is that for each new text that exists on the first column (FIG ITEM), it should be the start of the new row.
Have tried both flavors but not sure which is the best approach.
Link for original file here:
Logic intended
Thank you.
You could try using pdfplumber - it allows you to customize all of its table extraction settings.
For example - changing just the default horizontal strategy to text produces:
table = page.extract_table(table_settings={"horizontal_strategy": "text"})
[['FIG', '', '', 'EFFECT', 'UNITS'],
['ITEM', 'PART NUMBER', '1234567 NOMENCLATURE', 'FROM TO', 'PER\nASSY'],
['', '', '', '', ''],
['1', '', '', '', ''],
['', '', 'SYSTEM INSTL-AIR DISTR MIX', '', ''],
['', '', 'BAY (MAIN AIR', '', ''],
['', '', 'DISTRIBUTION ONLY)', '', ''],
You could play around with more settings to see if it's possible to extract the whole table the way you intend.
From here though - you could manually clean up and extract the column rows:
>>> df = pd.DataFrame(table)
>>> (df.iloc[0] + " " + df.iloc[1]).str.replace("\n", " ").str.strip()
0 FIG ITEM
1 PART NUMBER
2 1234567 NOMENCLATURE
3 EFFECT FROM TO
4 UNITS PER ASSY
dtype: object
df.columns = (df.iloc[0] + " " + df.iloc[1]).str.replace("\n", " ").str.strip()
df = df.tail(-3)
You could then forward fill the FIG ITEM column and group on that - allowing you to combine the items.
df.groupby(df["FIG ITEM"].replace("", float("nan")).ffill()).agg({
"PART NUMBER": "first",
"1234567 NOMENCLATURE": "\n".join,
"UNITS PER ASSY": "first",
})
PART NUMBER 1234567 NOMENCLATURE UNITS PER ASSY
FIG ITEM
- 1 M0DREF452754 SYSTEM INSTL-AIR DISTR MIX\nBAY (MAIN AIR\nDIS... RF
1 \nSYSTEM INSTL-AIR DISTR MIX\nBAY (MAIN AIR\nD...
10 BACS12GU3K8 .SCREW 12
15 BACS12GU3K9 .SCREW 18
20 BACB30NM3K15 .BOLT 15
27 BACB30NM3K17 .BOLT 2
28 BACB30NM3K20 .BOLT 1
30 NAS1149D0332J .WASHER 60
35 BACW10P44AL .WASHER 2
40 PLH53CD .NUT-\nSUPPLIER CODE:\nVF0224\nSPECIFICATION N... 2
45 SLT8LHC6 .STRAP-\nSUPPLIER CODE:\nV06383\nTRUE PART NUM... 7
5 BACS12GU3K7 .SCREW 12
import random
capitals = {'Alabama': 'Montgomery', 'Alaska': 'Juneau', 'Arizona': 'Phoenix',
'Arkansas': 'Little Rock', 'California': 'Sacramento', 'Colorado': 'Denver',
'Connecticut': 'Hartford', 'Delaware': 'Dover', 'Florida': 'Tallahassee',
'Georgia': 'Atlanta', 'Hawaii': 'Honolulu', 'Idaho': 'Boise', 'Illinois':
'Springfield', 'Indiana': 'Indianapolis', 'Iowa': 'Des Moines', 'Kansas':
'Topeka', 'Kentucky': 'Frankfort', 'Louisiana': 'Baton Rouge', 'Maine':
'Augusta', 'Maryland': 'Annapolis', 'Massachusetts': 'Boston', 'Michigan':
'Lansing', 'Minnesota': 'Saint Paul', 'Mississippi': 'Jackson', 'Missouri':
'Jefferson City', 'Montana': 'Helena', 'Nebraska': 'Lincoln', 'Nevada':
'Carson City', 'New Hampshire': 'Concord', 'New Jersey': 'Trenton', 'NewMexico': 'Santa Fe', 'New York': 'Albany', 'North Carolina': 'Raleigh',
'North Dakota': 'Bismarck', 'Ohio': 'Columbus', 'Oklahoma': 'Oklahoma City',
'Oregon': 'Salem', 'Pennsylvania': 'Harrisburg', 'Rhode Island': 'Providence',
'South Carolina': 'Columbia'}
for quizNum in range(10):
quizFile = open('capitalsquiz%s.txt' % (quizNum + 1), 'w')
answerKeyFile = open('capitalsquiz_answers%s.txt' % (quizNum + 1), 'w')
quizFile.write('Name:\n\nDate:\n\nPeriod:\n\n')
quizFile.write((' ' * 20) + 'State Capitals Quiz (Form %s)' % (quizNum + 1))
quizFile.write('\n\n')
states = list(capitals.keys())
random.shuffle(states)
for questionNum in range(40):
correctAnswer = capitals[states[questionNum]]
wrongAnswers = list(capitals.values())
del wrongAnswers[wrongAnswers.index(correctAnswer)]
wrongAnswers = random.sample(wrongAnswers, 3)
answerOptions = wrongAnswers + [correctAnswer]
random.shuffle(answerOptions)
quizFile.write('%s. What is the capital of %s?\n' % (questionNum + 1,states[questionNum]))
for i in range(4):
quizFile.write(' %s. %s\n' % ('ABCD'[i], answerOptions[i]))
quizFile.write('\n')
answerKeyFile.write('%s. %s\n' % (questionNum + 1, 'ABCD'[answerOptions.index(correctAnswer)]))
quizFile.close()
answerKeyFile.close()
The remaining 9 booklets are created as .txt files but are blank. Where am I going wrong ?
Questions involve the capital cities of U.S.A
Expected file form is :
Name:
Date:
Period:
State Capitals Quiz (Form 1)
What is the capital of West Virginia?
A. Hartford
B. Santa Fe
C. Harrisburg
D. Charleston
What is the capital of Colorado?
A. Raleigh
B. Harrisburg
C. Denver
D. Lincoln
3......
and so on . Like that for all the other files(remaining 9 .txt files which get created) questions would have to be printed.But they just turn out to be blank.
Each question booklets has the same questions but are in different order(to prevent cheating)
You questions loop is outside of the file loop. This is causing all of the files to be opened before any questions are written, then the last opened file is what gets the questions 👍
I can post the fix later if needed, just on my phone right now.
I am looking to get the value of the description field inside the weather.
{'coord': {'lon': 73.85, 'lat': 18.52}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'base': 'stations', 'main': {'temp': 305.381, 'pressure': 949.7, 'humidity': 31, 'temp_min': 305.381, 'temp_max': 305.381, 'sea_level': 1023.73, 'grnd_level': 949.7}
i have seen many posts and i am trying to do the below:
r1 = requests.get('http://api.openweathermap.org/data/2.5/weather?q=Pune,in&APPID=5ad6ec2537bfb0d574363e115c2d0041')
print(r1.status_code)
json_data = json.loads(r1.text)
print(json_data)
print("Weather is" ,json_data["weather"][0])
But the above is fetching me all the values inside the dictionary.
What's the best way to achieve that?
Thanks.
Use json_data["weather"][0]['description'] to access the description field.
I created a new activity "alu_in_no" as the following code:
alu_in_eu = w.get_one(data, w.equals('location','IAI Area, EU27 & EFTA'), w.contains("name", "aluminium production, primary, liquid, prebake"))
alu_in_no = w.transformations.geo.copy_to_new_location(alu_in_eu, 'NO')
data.append(alu_in_no)
w.transformations.geo.relink_technosphere_exchanges(
alu_in_no,
data,
contained=False
)
The new activity has the following exchange:
{'amount': 14.65,
'loc': 14.65,
'location': 'IAI Area, EU27 & EFTA',
'name': 'market for electricity, medium voltage, aluminium industry',
'pedigree': {'completeness': 1,
'further technological correlation': 1,
'geographical correlation': 1,
'reliability': 1,
'temporal correlation': 3}
I want to delete this exchange in this activity and replace a new one, for example:
{'amount': 1.0,
'loc': 1.0,
'location': 'NO',
'name': 'market for electricity, medium voltage',
'product': 'electricity, medium voltage',
'production volume': 131798608305.945,
'type': 'production',
'uncertainty type': 0,
'unit': 'kilowatt hour'}
In other word, I want to unlink the previous activity and link another activity? I believe there must be some functions in wurst can do it but I cannot find.
Thanks in advance!
The list of exchanges is a normal list, so you can delete the exchange the same way you would delete from any other list, e.g. del my_list[some_index or my_list = [x for x in my_list if some_condition_on_x(x)].
You would need to relink your new exchange, but you already know how to do this: relink_technosphere_exchanges. You can run it more than once, it won't change exchanges which are linked already.
I was wondering if anyone knew how to add numbers (purely for reference) to Kivy's FileChooserListView such that the file list is displayed like:
# Name Size
1. File 1 2k
2. File 2 2k
3. File 3 2k
...
OK, it's not a perfect answer but here's what I tried to do:
First thing was to edit kivy's default filechooser.py file. Find this section:
ctx = {'name': basename(fn),
'get_nice_size': get_nice_size,
'path': fn,
'controller': wself,
'isdir': self.file_system.is_dir(fn),
'parent': parent,
'sep': sep}
and change it to:
ctx = {'name': basename(fn),
'get_nice_size': get_nice_size,
'path': fn,
'controller': wself,
'isdir': self.file_system.is_dir(fn),
'parent': parent,
'sep': sep,
'index': index}
Next up, find kivy's style.kv file (you could probably create a custom class to do this but I was being lazy!). Look for this section [FileListEntry#FloatLayout+TreeViewNode]:
I then took this part:
Label:
id: filename
text_size: self.width, None
halign: 'left'
shorten: True
text: ctx.name
and changed it to:
Label:
id: filename
text_size: self.width, None
halign: 'left'
shorten: True
text: "{}. {}".format(ctx.index, ctx.name)
As per my comment above, it seems to throw an error if you try to navigate folders.
It may be the case that one of the kivy experts knows a better way of doing this.
I know this is quite late but to complete the answer of elParaguayo, you also have to replace the lines
pardir = self._create_entry_widget(dict(
name=back, size='', path=new_path, controller=ref(self),
isdir=True, parent=None, sep=sep,
get_nice_size=lambda: ''))
with
pardir = self._create_entry_widget(dict(
name=back, size='', path=new_path, controller=ref(self),
isdir=True, parent=None, sep=sep,
get_nice_size=lambda: '', index= 0))
(be careful there are 2 occurences of these lines). This is what throws the exception when you navigate: the parent directory ../ is not created with the same lines as the other files.
Also, I would advise to create a local copy of filechooser.py and style.kv and load them into your app instead of modifying the source code of the kivy modules.